フィルターのクリア

How do I combine 2d matrices mat files into a single 3d matrices file?

41 ビュー (過去 30 日間)
Fadilla Atyka Nor Rashid
Fadilla Atyka Nor Rashid 2018 年 8 月 13 日
コメント済み: Stephen23 2022 年 1 月 14 日
I have a number of 240 x 320 double mat files. I wanted to combine around 30 of them to make it a single 3d mat file resulting to 240x320x30 double.
I have tried below codes, but something went wrong because all the values inside the files turns out to be zero and thats disrupt my output. Can someone helps me with this? Thank you in advance!
d=(240,320,30);
for k=1:30
d(:,:,k);
end
  4 件のコメント
Stephen23
Stephen23 2018 年 8 月 13 日
@Fadilla Atyka Nor Rashid: your question does not contain enough information. How many variables are saved in each .mat file? Do they have the same name/s in each .mat file?
Fadilla Atyka Nor Rashid
Fadilla Atyka Nor Rashid 2018 年 8 月 13 日
@kssv i have more than that but i wanna make it 3d matrices resulting to 240x320x30 (30 is the Number of frames)
@Dennis, thats why it looks like something wrong with my code. hehe
@Stephen each .mat file consists of 240x320uint16 yeah, they do have same name in each .mat file.

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

採用された回答

Stephen23
Stephen23 2018 年 8 月 13 日
編集済み: Stephen23 2018 年 8 月 13 日
Something like this should get you started. This will load the data from all of the .mat files in the specified directory, concatenate their data, and then save the concatenated array as a new .mat file:
D = 'path to where the files are';
S = dir(fullfile(D,'*.mat'));
N = numel(S);
C = cell(1,N);
for k = 1:N
T = load(fullfile(D,S(k).name));
C{k} = T.fieldname; % pick the fieldname to suit.
end
A = cat(3,C{:});
save('array.mat','A')
See also:
  30 件のコメント
Neda Deljavan
Neda Deljavan 2022 年 1 月 13 日
Hi Stephen,
I’m filtering my data and extracting features. I’ve done for 7 similar files with same codes, but for one file I’ve got this error which is about ‘filtfilt’ function.
What should I do?
Stephen23
Stephen23 2022 年 1 月 14 日
"What should I do?"
FILTFILT apparently expects its inputs to be finite. Ergo, what you should do is provide it with finite inputs.

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

その他の回答 (1 件)

Christian Heigele
Christian Heigele 2018 年 8 月 13 日
編集済み: Christian Heigele 2018 年 8 月 13 日
I would use cat.
If you want to list them explicitly:
A1 = rand(3,3);
A2 = rand(3,3);
A3 = rand(3,3);
A_all1 = cat(3, A1, A2, A3);
If you have them in some kind of array / parse them from files: (Thanks Steven, that is much cleaner...)
A = {};
A{1} = rand(3,3);
A{2} = rand(3,3);
A{3} = rand(3,3);
A_all2 = cat(3, A{:});

カテゴリ

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