loop in two matrices for extracting values and plot lines

1 次查看(过去 30 天)
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])

采纳的回答

Voss
Voss 2022-12-8
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by