how can I choose values from a vector ascendingly and concequently ?

조회 수: 1 (최근 30일)
omar th
omar th 2022년 7월 15일
댓글: Voss 2022년 7월 15일
X = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479]

채택된 답변

Voss
Voss 2022년 7월 15일
X = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479]
X = 1×20
-28.6479 -27.5000 -18.3300 -13.7500 -11.0000 -9.1600 -7.8500 -6.8700 -6.1100 -5.5000 5.5000 6.1100 6.8700 7.8500 9.1600 11.0000 13.7500 18.3300 27.5000 28.6479
% choose three consecutive elements from X, starting with element 5:
choice = X(5:7)
choice = 1×3
-11.0000 -9.1600 -7.8500
  댓글 수: 2
omar th
omar th 2022년 7월 15일
first thank you for your fast response, but I want to choose only one value each iteration because this vector inside while loop. for example, in the first step I want choose -28.6479 in the second step I want to choose -27.5 and so forth up to choosing the final value in the vector which is -28.6479
Voss
Voss 2022년 7월 15일
X = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479]
X = 1×20
-28.6479 -27.5000 -18.3300 -13.7500 -11.0000 -9.1600 -7.8500 -6.8700 -6.1100 -5.5000 5.5000 6.1100 6.8700 7.8500 9.1600 11.0000 13.7500 18.3300 27.5000 28.6479
for current_index = 1:numel(X)
choice = X(current_index)
end
choice = -28.6479
choice = -27.5000
choice = -18.3300
choice = -13.7500
choice = -11
choice = -9.1600
choice = -7.8500
choice = -6.8700
choice = -6.1100
choice = -5.5000
choice = 5.5000
choice = 6.1100
choice = 6.8700
choice = 7.8500
choice = 9.1600
choice = 11
choice = 13.7500
choice = 18.3300
choice = 27.5000
choice = 28.6479

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by