Effacer les filtres
Effacer les filtres

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

41 vues (au cours des 30 derniers jours)
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 commentaires
Stephen23
Stephen23 le 13 Août 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 le 13 Août 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.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 13 Août 2018
Modifié(e) : Stephen23 le 13 Août 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 commentaires
Neda Deljavan
Neda Deljavan le 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 le 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.

Connectez-vous pour commenter.

Plus de réponses (1)

Christian Heigele
Christian Heigele le 13 Août 2018
Modifié(e) : Christian Heigele le 13 Août 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{:});

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by