loop inside Index of matrix

조회 수: 1 (최근 30일)
Harel Harel Shattenstein
Harel Harel Shattenstein 2015년 5월 12일
답변: Walter Roberson 2015년 5월 12일
On the following code
function [d] = matrix( n )
d=zeros(2*n-1);
for i=1:n
d(i:end-i+1,i:end-i)=i;
end
end
How does the following runs?
d(i:end-i+1,i:end-i)=i;
first the rows index increase or the columns? or both at the same time?

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 12일
MATLAB always goes columns first when there is a range. But it doesn't matter when you are assigning a scalar to the block, as all elements of the block are going to be given the same result.

추가 답변 (0개)

카테고리

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