How can I find the difference between two plots with a dimensional mismatch ?

Hello all,
I have a question that I don't know if there is a solution off the bat.
Here it goes,
I have two data sets, that I have plotted on the same figure. I need to find their difference, simple so far... the problem arises in the fact that say matrix A has 1000 data points while the second (matrix B) has 580 data points. How will i be able to find the difference between the two graphs since their is a dimensional miss match between the two figures.
One way that I thought of is artificially inflating matrix B to 1000 data points, but the trend of the plot will remain the same. Would this be possible? and if yes how?

Answers (1)

all_x = unique([x_from_A(:); x_from_B(:)]);
refined_A = interp1(x_from_A, A, all_x);
refined_B = interp1(x_from_B, B, all_x);
plot(all_x, refined_B - refined_A)

2 Comments

does this come with an explenation of what exactly the solution to my problem is?
THanks BTW :)
Yeah I see what you did but extending the range of the matrix with NaN'S doesn't really work when you later whant to subtract them, take for example this code:
A=[1 2 3 4 5 ];
B=[11 22 33 44 55 66 77 88 99 1010];
Ya=A.*20+4;
Yb=B./10+3;
all_x = unique([A(:); B(:)])
refined_A = interp1(A, Ya, all_x);
refined_B = interp1(B, Yb, all_x);
C=refined_B - refined_A
plot(A,Ya,'r',B,Yb)
xlim([-100 1000])
grid on hold on
plot(all_x, C)
you will notice that the cells of C are filled with NaN's...
Do you have any suggestions on how to bypass this problem?

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 5 Aug 2015

Edited:

on 5 Aug 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!