loop in two matrices for extracting values and plot lines

조회 수: 3 (최근 30일)
Enzo
Enzo 2022년 12월 8일
답변: Voss 2022년 12월 8일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by