Error using plot Vectors must be the same length.

1 Ansicht (letzte 30 Tage)
IMC
IMC am 19 Jun. 2021
Bearbeitet: dpb am 19 Jun. 2021
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.

Antworten (1)

dpb
dpb am 19 Jun. 2021
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 Kommentare
IMC
IMC am 19 Jun. 2021
Unfortunately, I didn't get the line plot. This is the figure I got after using above lines of code:
dpb
dpb am 19 Jun. 2021
Bearbeitet: dpb am 19 Jun. 2021
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by