how can i save row value in variable like x(1)
Show older comments
i have metric row =[1 1 0 0; 1 1 0 0; 0 1 1 0 ; 1 1 0 0] how i can make x(1)=1 1 0 0 and x(2)= 1 1 0 0 and so on
Accepted Answer
More Answers (1)
Walter Roberson
on 2 Mar 2016
What you ask is not possible in MATLAB. You two options (using a for loop) are:
for i = 1 : 4
x(i,:) = row(i,:)
end
or
for i = 1 : 4
x{i} = row(i,:);
end
In the first of those options, you would need to access x(1,:) to get the first row as a numeric vector.
In the second of those options, you would need to access x{1} to get the first row as a numeric vector. Notice that is not x(1), it is x{1}. If you were to use x(1) then what you would get would be {[1 1 0 0]} which is a cell array containing the vector rather than the vector itself.
Categories
Find more on Matrices and Arrays 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!