How do I put my row vector answers into a matrix?
13 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Image Analyst
2013 年 1 月 27 日
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.
0 件のコメント
その他の回答 (1 件)
Cedric
2013 年 1 月 27 日
編集済み: Cedric
2013 年 1 月 27 日
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!