필터 지우기
필터 지우기

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

조회 수: 13 (최근 30일)
Hi, How to plot vectors with different sizes against each other ? size of one vector is 24244x1 and other vector is 24243x1
  댓글 수: 3

댓글을 달려면 로그인하십시오.

답변 (3개)

the cyclist
the cyclist 2018년 5월 21일
편집: the cyclist 2018년 5월 21일
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
Sameera Rayapudi
Sameera Rayapudi 2023년 5월 3일
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
Steven Lord 2018년 5월 21일
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 2020년 4월 29일
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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by