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?
39 次查看(过去 30 天)
显示 更早的评论
Saraswatula Sai Pavan Sastry Sastry SOME
2018-9-23
评论: Saraswatula Sai Pavan Sastry Sastry SOME
2018-9-25
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 个评论
回答(2 个)
KALYAN ACHARJYA
2018-9-23
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;
Image Analyst
2018-9-23
编辑:Image Analyst
2018-9-23
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!