append different matrices in a for loop

4 ビュー (過去 30 日間)
Fatma Nur Disci
Fatma Nur Disci 2020 年 12 月 16 日
編集済み: Ameer Hamza 2020 年 12 月 16 日
Hi ,
I have a matrix 3x1024 . And I need to append all data in a for loop 128 times. so want to size of all 384x1024.
Could you help me ?
Thank you !
a = load('x.mat');
b = load('y.mat');
c = load('z.mat');
for i =1:128
% l = (i-1)*3+1;
% m = i*3;
first = a.ss(:,i,:); % a.ss =1024x128
second = b.kk(:,i,:);% b.kk =1024x128
third = c.zz(:,i,:); % c.zz = 1024x128
first = transpose(first); % now size of first = 1x1024
second = transpose(second); % now size of second = 1x1024
third = transpose(third); % now size of third = 1x1024
% all(l:m) = [first;second;third]; % size of all = 3x1024, want size of all to be 384x1024
all = [first;second;third];
end

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 16 日
編集済み: Ameer Hamza 2020 年 12 月 16 日
One option is to create a cell array to save data in each iteration and then combine it in the form of a vector at the end. See my answer to this question here: https://www.mathworks.com/matlabcentral/answers/695740-output-of-fun-is-not-a-matrix-the-same-size-as-the-block-in-block-proc#answer_577455
More specifically, something like this
a = load('x.mat');
b = load('y.mat');
c = load('z.mat');
C = cell(1,128);
for i =1:128
% l = (i-1)*3+1;
% m = i*3;
first = a.ss(:,i,:); % a.ss =1024x128
second = b.kk(:,i,:);% b.kk =1024x128
third = c.zz(:,i,:); % c.zz = 1024x128
first = transpose(first); % now size of first = 1x1024
second = transpose(second); % now size of second = 1x1024
third = transpose(third); % now size of third = 1x1024
% all(l:m) = [first;second;third]; % size of all = 3x1024, want size of all to be 384x1024
C{i} = [first;second;third];
end
all = vertcat(C{:})

その他の回答 (0 件)

カテゴリ

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