HELLO.I need to find the difference between two plots in the same graph(deviation between model and experiment) and find the deviation between them. Can anyone please me how to do this?
Show older comments
I have tried to take in points from the graph using digitializer but the array of points obtained from the respective plots seem to be of unequal size. So when I find the difference there is an error "matrix dimensions must agree".
4 Comments
KALYAN ACHARJYA
on 23 Sep 2018
Can you share the plots figure? or similar representation code
Saraswatula Sai Pavan Sastry Sastry SOME
on 23 Sep 2018
KALYAN ACHARJYA
on 23 Sep 2018
Here 4 plots, which two plots?
Saraswatula Sai Pavan Sastry Sastry SOME
on 23 Sep 2018
Answers (2)
Image Analyst
on 23 Sep 2018
Edited: Image Analyst
on 23 Sep 2018
This should do it. It works by getting a common x axis that has all the x coordinates from BOTH sets of your coordinates, i.e., by combining x1 and x2. Then it gets new y values by adding in, through interpolation, the y values from that set at the newly added x values from the other set of coordinates.
% Get the first set of data. Just use random coordinates for this demo.
n1 = 10
x1 = sort(rand(1, n1), 'ascend');
y1 = rand(1, n1);
% Get the second set of data. Just use random coordinates for this demo.
n2 = 15
x2 = sort(rand(1, n2), 'ascend');
y2 = rand(1, n2);
% Now we have our data and we can begin.
% Get the length of the first set of data.
length1 = length(x1);
% Get the length of the second set of data.
length2 = length(x2);
% Merge the two x axes.
x = sort([x1, x2], 'ascend');
% Get new y1 values by interpolating the y value
% at the newly added x2 coordinates
y1New = interp1(x1, y1, x);
% Get new y2 values by interpolating the y value
% at the newly added x1 coordinates
y2New = interp1(x2, y2, x);
% Plot things:
plot(x1, y1, 'rd-', 'LineWidth', 14);
hold on;
plot(x2, y2, 'bo-', 'LineWidth', 14);
plot(x, y1New, 'm*-', 'LineWidth', 2);
plot(x, y2New, 'c*-', 'LineWidth', 2);
legend('Set 1', 'Set2', 'Interpolated set 1', 'Interpolated set 2');
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
Then, now that they have a common x, you can just compute the difference as y2New-y1New or whatever you want.
1 Comment
Saraswatula Sai Pavan Sastry Sastry SOME
on 25 Sep 2018
KALYAN ACHARJYA
on 23 Sep 2018
For Difference, vector sizes must be the same. You can do the sorts of interpolation to make the both vectors having same size.
t=0:.1:10;
y1=sin(t);
plot(y1);
hold on;
y2=exp(t);
plot(y2);
y3=y1-y2;
plot(y3);
legend('sin(t)','exp(t)','y3(diff)');
hold off;
1 Comment
Saraswatula Sai Pavan Sastry Sastry SOME
on 25 Sep 2018
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!