loop inside Index of matrix

1 Ansicht (letzte 30 Tage)
Harel Harel Shattenstein
Harel Harel Shattenstein am 12 Mai 2015
Beantwortet: Walter Roberson am 12 Mai 2015
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Mai 2015
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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by