필터 지우기
필터 지우기

what is the meaning of A(:,:,1:2:3);

조회 수: 100 (최근 30일)
shivu P
shivu P 2017년 6월 20일
댓글: Walter Roberson 2022년 3월 10일
didnt get the meaning of 1:2:3 clearly.
  댓글 수: 1
Stephen23
Stephen23 2017년 6월 20일
편집: Stephen23 2017년 6월 20일
Did you try it:
>> 1:2:3
ans =
1 3
And read the documentation?:

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

답변 (3개)

Walter Roberson
Walter Roberson 2017년 6월 20일
X = A : B : C
is like
X = [];
temp = A;
if B > 0
while temp <= C
X = [X, temp];
temp = temp + B;
end
elseif B < 0
while temp >= C
X = [X, temp];
temp = temp + B;
end
end
In the case of 1:2:3, with positive increment, you check whether 3 is less than 1, and since it is not less than your result will have at least one result in it. Start with the 1 in the list. Add the increment, 2, to that value. The result, 3, is not greater than the end point (3), so add the result to the list, so the list is [1 3] now. Add the increment 2 to that last value, getting 5. 5 is greater than the end point of 3, so stop. The list is finished.
Another way of saying this is: the numbers starting at 1, and no more than 3, that are 2 apart from each other. 1 and 3 satisfy that so they are both included.
  댓글 수: 1
Jan
Jan 2017년 6월 20일
+1 for the last sentence, which is a rare case of English being leaner and more clear then Matlab.

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


YOGESH RAMESH
YOGESH RAMESH 2020년 9월 5일
B(1:2,3)
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 9월 8일
As examined above, 1:2:3 is the list of numbers that includes 1 and 3. You would then index B at locations 1 and 3. Linear indexing would be used, so if B were 2 x 4
b11 b12 b13 b14
b21 b22 b23 b24
then entry #1 and #3 would be b11 and b12

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


Mustafa  Ahmed
Mustafa Ahmed 2022년 3월 10일
c = 1:2:5
c = 1×3
1 3 5
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 3월 10일
The numbers starting at 1, and 2 apart, and do not exceed 5. So 1, 3, 5

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by