evaluate the % difference between a previous and a new result in matlab

To evaluate the percentage difference between a previous and a new result in matlab, you can use the following formula:

main.m
percent_diff = abs((new_result - prev_result) / prev_result) * 100;
68 chars
2 lines

where new_result is the new result and prev_result is the previous result. The abs function is used to take the absolute value of the percentage difference.

Here's an example code:

main.m
prev_result = 50;
new_result = 75;

percent_diff = abs((new_result - prev_result) / prev_result) * 100;

disp(percent_diff); % Output: 50
138 chars
7 lines

In this example, the previous result is 50 and the new result is 75. The percentage difference between these two values is calculated to be 50.

related categories

gistlibby LogSnag