MATLAB: How to extract rows from matrix in a for loop

for loopindexing

I have a n x m -matrix and want extract each line of the matrix in a for-loop. In each step one row should be extracted, in the next step the next row and so on …
I tried:
a = [ 1 2 3 4; 4 5 6 4; 1 1 1 1; 6 3 5 7];
lines = @(x) size(x,1); % lines(x) calculates number of lines in matrix x
for i = 1 : lines(a);
profrow = a(i,:);
t = profrow(i);
end
r = [t]
I want that the vector profrow(i) contains always one line of the matrix. But in the end it only contains one element (The element a(i,i)). Anybody know why and/or can help me how to do what I want? Thx.

Best Answer

Within the loop, profrow does contain the ith row as you indeed want. Your code is correct. t is then the ith element of that row, so indeed t does contain a(i,i), but profrow is exactly what you ask.
After the loop, profrow is only the last row.