필터 지우기
필터 지우기

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

조회 수: 41 (최근 30일)
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by