Matrix data

5 views (last 30 days)
Jw
Jw on 11 Jan 2012
I have a 5x5 matrix
lets say i initialise my x=tmp([1;2;4]); as my initial state i only want the first column and row 1 2 and 4 data.
I am doing a looping and how do i get the data in my loop to get column 2 row 1 2 and 4 data in my 2nd loop and the subsequent column in my subsequent looping?
I only need the row 1 2 and 4 data for each column during each increment of my loop
thanks.

Accepted Answer

Chandra Kurniawan
Chandra Kurniawan on 11 Jan 2012
A = round(10*rand(5,5))
tmp = [1 2 4];
for col = 1 : 5
B(:,col) = A(tmp,col);
end
The result :
A =
9 4 1 9 1
1 9 9 6 2
4 2 6 4 1
3 3 5 5 2
8 1 1 4 2
B =
9 4 1 9 1
1 9 9 6 2
3 3 5 5 2

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!