loop in two matrices for extracting values and plot lines

2 Ansichten (letzte 30 Tage)
Enzo
Enzo am 8 Dez. 2022
Beantwortet: Voss am 8 Dez. 2022
Hello everyone,
I would like to extract the values stored in 2 different matrices and use them in order to create a line (plot). One point should be always the same (I1,M1) where I1 is the x coordinate and M1 is the Y.
inside J and WZ matrices, I have, let's say, 3 values each (but they could be more or less) and I would like to use them in order to create 3 different lines with one point constant (I1, M1) while the others change. PLease note that, I would like to add 2500 to all the values stored inside WZ.
J = [2.5 27 56];
WZ = [12.2 23.2 33];
M1 = 22
I1 = 2600
in this specific case, I would end up with 3 lines as follow:
line_1 = line([I1;(12.2+2500)],[M1;2.5])
line_2 = line([I1;(23.2+2500)],[M1;27])
line_3 = line([I1;(33+2500)],[M1;56)
the following line of code is useless as I get the following results: Dimensions of arrays being concatenated are not consistent.
thanks for your help!
for peaks = length(WZ)
plot([I1;(WZ+2500)],[M1;J])

Akzeptierte Antwort

Voss
Voss am 8 Dez. 2022
J = [2.5 27 56];
WZ = [12.2 23.2 33];
M1 = 22;
I1 = 2600;
for ii = 1:numel(WZ)
line([I1;WZ(ii)+2500],[M1;J(ii)]);
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by