Effacer les filtres
Effacer les filtres

Hi,How to plot vectors with different sizes against each other ? size of one vector is 24244x1 and other vector is 24243x1

13 vues (au cours des 30 derniers jours)
Hi, How to plot vectors with different sizes against each other ? size of one vector is 24244x1 and other vector is 24243x1
  3 commentaires

Connectez-vous pour commenter.

Réponses (3)

the cyclist
the cyclist le 21 Mai 2018
Modifié(e) : the cyclist le 21 Mai 2018
The correct way to do this depends on how the two vectors relate to each other. Take a smaller example. Suppose my two vectors are v1 = [1 2 3 4] and v2 = [4 6 8].
I could plot the first three elements of v1 against v2. (This is what the code in gabriella's comment would do.) Or I could plot the last three elements of v1 against v2. Or I could plot all elements of both vectors on a normalized scale, such that the first and last elements of the two vectors line up with each other.
Which approach is most accurate will depend on the relative relationship of v1 and v2. You need to give more info for us to be more specific.
  1 commentaire
Sameera Rayapudi
Sameera Rayapudi le 3 Mai 2023
As mentioned above (in cyclist's comment), I want to plot my two vectors of different lengths on a normalized scale, such that the first and last elements of the two vectors line up with each other. Can someone help me with how to do that?

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 21 Mai 2018
Since one of the vectors is one element shorter than the other, I suspect the shorter is the result of using diff on the longer. If that's the case, take a look at the "Approximate Derivatives with diff" example on that documentation page. Note that when plotting X versus Y and Z, we only plot using part of X. That's to account for this behavior on the output: "If X is a nonempty array, then the dimension of X acted on by diff is reduced in size by n in the output."
If you didn't use diff to generate the shorter vector, then along the lines of what the cyclist said you need to either shorten the longer vector by eliminating one element or lengthen the shorter vector by padding with 0, NaN, or something else.

Michael Mauersberger
Michael Mauersberger le 29 Avr 2020
Hi,
maybe you want to plot one vector v of length xv over a vector u of length xu. Then you can interpolate. It is assumed, that u is not equally distributed.
u = [1,2,8,16];
v = [6,4,3,5,2,1,6];
% Interpolate the v-vector to positions in u
u_ = interp1q((1:size(u,2))',u',linspace(1,size(u,2),size(v,2))');
% Interpolate the new v_-vector to u
v_ = interp1q(u_,v',u');
figure
clf
hold on
plot(u,v_) % 1st plot
plot(u_,v) % 2nd plot
You see in the 1st plot, that you only have that amount of data of the smaller vector.
The 2nd plot seems more promising... But you have no information about the further distribution of the abscissa u.
Best regards,
Michael

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by