Error using plot Vectors must be the same length.

2 次查看(过去 30 天)
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 中查找有关 Scatter Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by