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

 채택된 답변

Image Analyst
Image Analyst 2013년 1월 27일

1 개 추천

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.

추가 답변 (1개)

Cedric
Cedric 2013년 1월 27일
편집: Cedric 2013년 1월 27일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2013년 1월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by