Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

Walter Roberson
Walter Roberson il 5 Ago 2015
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 Commenti
Giorgos
Giorgos il 5 Ago 2015
does this come with an explenation of what exactly the solution to my problem is?
THanks BTW :)
Giorgos
Giorgos il 5 Ago 2015
Modificato: Giorgos il 5 Ago 2015
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?

Accedi per commentare.

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by