How to build matrix

2 ビュー (過去 30 日間)
Yulia
Yulia 2014 年 3 月 17 日
コメント済み: Yulia 2014 年 3 月 17 日
Dear all! I have the following problem. I have 4 values A,B,C,D each value has the size [3 x 1000]. A need to built matrix [A B; C D], which M [A(m,n) B(m,n); C(m,n) d(m,n)]. How to do it? NOw I have only the last result the code I have now :
if true
freq_points= 1000;
n = 3;
A = zeros(n,freq_points);
B = zeros(n,freq_points);
C = zeros(n,freq_points);
D = zeros(n,freq_points);
B = ones (n, freq_points);
for r =1:3
for la = 1:1:freq_points;
A(r,:) = exp(gamma(r,:).*d(r));
B(r,:) = 1;
C(r,:) = exp((-gamma(r,:)).*d(r))*(1/Z(r));
D(r,:) = -1/Z(r);
M = [A(r,la) B(r,la); C(r,la) D(r,la) ]
end;
end
  2 件のコメント
dpb
dpb 2014 年 3 月 17 日
First format your code so we can read it...keep at it until it looks right in the preview window.
Image Analyst
Image Analyst 2014 年 3 月 17 日

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2014 年 3 月 17 日
Take M outside the loop and do
M = [A B; C D];
So M is only created after A, B, C, and D have finished being created.
  1 件のコメント
Yulia
Yulia 2014 年 3 月 17 日
in this case I have the answer with dimension[6:2000]. And it looks like :[A(1) A(2) A(3) D(1)D(2)D(3) ]

サインインしてコメントする。


Yulia
Yulia 2014 年 3 月 17 日
I decided to make like this:
if true
for r = 1:3
for la = 1:1:freq_points
A(r,:) = exp(gamma(r,:).*d(r));
B(r,:) = 1;
C(r,:) = exp((-gamma(r,:)).*d(r))*(1/Z(r));
D(r,:) = -1/Z(r);
%D(r) = [D(r)];
M = [A(r,la) B(r,la); C(r,la) D(r,la) ];
FG (:,:,la) = M;
end
But now I do not know how to save all this all the matrices for r=1, r=2, r=3. NOw i can have only r = 3

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by