How do I put my row vector answers into a matrix?

I am wondering how I get my answers (x') which is a row vector into a matrix with 26 rows and 3 columns.
MATLAB CODE
V2=0;
V3=50;
W=zeros(26,3);
for V1=50:2:100;
b=[V1; V2; V3]
ans3=P*b;
y=L\ans3;
x=U\y;
x'
end
I want the final result to look something like this: W=[a1 b1 c1; a2 b2 c3; a3 b3 c3......a26 b26 c26] How do I get each of vectors into a matrix? Thank you for your help, Maddy

 Accepted Answer

Try this:
V2=0;
V3=50;
W=zeros(26,3);
P = 123; % Whatever...
L = 2; % Whatever...
U = 42; % Whatever...
count = 1;
for V1=50:2:100;
b=[V1; V2; V3]
ans3=P*b;
y=L\ans3;
x=U\y;
x'
% Insert x' into W
W(count, :) = x';
count = count+1;
end
W % Print it to the command line.

More Answers (1)

Cedric
Cedric on 27 Jan 2013
Edited: Cedric on 27 Jan 2013
If the rest of the computations is correct (P, L, U have appropriate dimensions), you would do something like
W(..., :) = x.' ;
with the ... a row index that you don't compute presently. You could build one the following way:
...
V1 = 50:2:100 ;
for ii = 1 : numel(V1)
b = [V1(ii); V2; V3] ;
...
W(ii,:) = x.' ;
end
There would be a more appropriate (vector) way for doing this computation I suspect, but let's first solve the issue of addressing rows of W.

Categories

Community Treasure Hunt

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

Start Hunting!