Converting a 10x10 matrix to a 100x1 vector
Show older comments
Currently, I have a 10x10 matrix displaying the geometry for a figure. I need to turn that 10x10 into a 100x1 vector for use in solving a linear equation. The order I need for this 100x1 is that the first row of the 10x10 would be 1-10 on the 100x1 vector, second row would be 11-20 etc. How can I do this in MATLAB? I feel like it should be a simple code, but I'm struggling with putting it together. Any help would be appreciated.
Answers (1)
Azzi Abdelmalek
on 1 Nov 2013
Edited: Azzi Abdelmalek
on 1 Nov 2013
If A is your matrix
B=A';
out=B(:)
%or
out=reshape(A',[],1)
3 Comments
Azzi Abdelmalek
on 1 Nov 2013
[Jhon commented]
that answer seems to be close, but it seems to shift my matrix up 1 and over one. Here is the code I have currently:
qdot = zeros(n);
for j=1:n
for k=1:n
if j>(0.3*n) && j<(0.8*n)
if k>(0.2*n) && k<=(0.6*n)
qdot(j,k) = 10000;
end
else
qdot(j,k) = 0;
end
end
end
which produces an nxn array
what I need to do is that that nxn array specifically and turn it into an n^2x1. The previous comment was really close, but it put the values in the wrong location
Azzi Abdelmalek
on 1 Nov 2013
The answer do what you've asked
Azzi Abdelmalek
on 1 Nov 2013
Unless you are confusing rows and columns, in this case
out=A(:)
Categories
Find more on Operators and Elementary Operations 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!