Can these operations be vectorized?

X=1:100;
T=zeros(10);
for i=1:10
T(i,:)=X((1+(i-1)*10):(10*i));
end
Please tell me how to do these operations without using the FOR Loop.

1 Kommentar

Matt Fig
Matt Fig am 15 Okt. 2012
Why did you use the Code button on your paragraph, but not on the code?? Please fix this.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Matt Fig
Matt Fig am 15 Okt. 2012

0 Stimmen

T = reshape(1:100,10,10).'

3 Kommentare

Sir, what I actually intended was that, the matrix X can have any arbitrary real value in it's indices and then how will I copy these values(10 at a time) to my matrix T, in Row wise order. Please suggest a solution. P.S. I hope I have made the syntax correction to the question posted.
Will this work ?
T=reshape(X,10,10);
Matt Fig
Matt Fig am 15 Okt. 2012
Give it a try! Did you notice that I took the transpose?
Vinod S
Vinod S am 16 Okt. 2012
Yes sir, it does work. Thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by