Error using plot Vectors must be the same length.

조회 수: 1 (최근 30일)
IMC
IMC 2021년 6월 19일
편집: dpb 2021년 6월 19일
Hello,
I am trying to plot Radius verses temperature in my code. Radius is matrix (2030x1354 double) and I just want to plot the radius where M_CP = 2 therefore I did indexing and result is a column vector 668557x1. I've searched that error is because of the different dimensions of x and y but I am unable to resolve this issue. Kindly suggest me what should I do to plot it correctly. Thank you.
M_CP = double(Data_CP); % 2030 x 1354 double (it has values 1, 2, 3 and 4)
M_CT = double(Data_CT); % 2030 x 1354 double
M_CRAD=double(Data_CRAD);
Radius = (M_CRAD).* 0.01; % 2030x1354 double
cldTT = (M_CT -(-15000)).* 0.01; % Converting from Kelvin to C
cldTT1 = cldTT- 273.15; % 2030x1354 double
index_liq = M_CP == 2; %index to find where M_CP ==2
M_RAD_LIQ = Radius(index_liq); % 668557x1 double
plot(M_RAD_LIQ,cldTT1)
Error using plot
Vectors must be the same length.

답변 (1개)

dpb
dpb 2021년 6월 19일
On the right track, just have to use the index for both variables...
index_liq = (M_CP==2); % index to find where M_CP ==2
plot(Radius(index_liq),cldTT1(index_liq)) % plot matching records
NB: You don't need the temporary variable to plot; it may well be convenient to create it for later use if doing a lot with it, but doing so instead of just using the logical addressing vector does create a copy in memory of the same data as already have (and the temperature variable along with it or any other variables of same condition). Since this is a pretty-decent-sized variable, that could have ramifications if done indiscriminantly.
  댓글 수: 2
IMC
IMC 2021년 6월 19일
Unfortunately, I didn't get the line plot. This is the figure I got after using above lines of code:
dpb
dpb 2021년 6월 19일
편집: dpb 2021년 6월 19일
Well, your data aren't in order, then, but with radii of given magnitudes all jumbled up in sequence...
Either use scatter() instead or plot() without a solid line or
index_liq = (M_CP==2); % index to find where M_CP ==2
[~,ixOrder]=sort(Radius(index_liq)); % get the sorted order of radius values
plot(Radius(index_liq(ixOrder)),cldTT1(index_liq(ixOrder))) % plot matching records in sorted order

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

카테고리

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