Filter löschen
Filter löschen

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

41 Ansichten (letzte 30 Tage)
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 Kommentare
Stephen23
Stephen23 am 13 Aug. 2018
@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 am 13 Aug. 2018
@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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 13 Aug. 2018
Bearbeitet: Stephen23 am 13 Aug. 2018
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 Kommentare
Neda Deljavan
Neda Deljavan am 13 Jan. 2022
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 am 14 Jan. 2022
"What should I do?"
FILTFILT apparently expects its inputs to be finite. Ergo, what you should do is provide it with finite inputs.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Christian Heigele
Christian Heigele am 13 Aug. 2018
Bearbeitet: Christian Heigele am 13 Aug. 2018
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{:});

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by