Hi,How to plot vectors with different sizes against each other ? size of one vector is 24244x1 and other vector is 24243x1
24 views (last 30 days)
Show older comments
Hi, How to plot vectors with different sizes against each other ? size of one vector is 24244x1 and other vector is 24243x1
3 Comments
Answers (3)
the cyclist
on 21 May 2018
Edited: the cyclist
on 21 May 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 Comment
Sameera Rayapudi
on 3 May 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?
Steven Lord
on 21 May 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.
0 Comments
Michael Mauersberger
on 29 Apr 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
0 Comments
See Also
Categories
Find more on Interpolation 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!