How to merger multiple .mat files consists of 2D matrix into 3D matrix

조회 수: 2 (최근 30일)
college student
college student 2021년 7월 10일
댓글: Stephen23 2021년 7월 11일
Hi everyone, I have 7 .mat files, which each files consists of 2D matrix (2048x22). I want to merger it into 2048x22x7. I already done it, but the value inside the matrix is 0, -0 like the image below.
I want to make layer like the image below.
I attach my .mat files, so anyone could see the matrix inside the matfiles. Could anyone help me? Thank you.
  댓글 수: 2
Simon Chan
Simon Chan 2021년 7월 10일
The values of most of the data are close to zero and hence it shows 0.0000 or -0.0000 when you display them. It seems to be normal.
Stephen23
Stephen23 2021년 7월 10일
편집: Stephen23 2021년 7월 10일
As Simon Chan already commented, most of your data are close to zero.
So it is not really a surprise, then when displayed to four decimal places, you will see a lot of zeros.
S = load('01.mat')
S = struct with fields:
data_matrix: [2048×22 double]
histogram(S.data_matrix(:))
Note that you can change the display format, and in the settings also the format used for the variable viewer.
"but the value inside the matrix is 0, -0"
In MATLAB a displayed 0 only ever means that the value is exactly zero. If the number has trailing zeros, like your data, then we know that the value is not exactly zero (even if the non-zero digits are too small to be shown with the current format precision).

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2021년 7월 10일
편집: Stephen23 2021년 7월 10일
Using the files from your comment, and assuming that the filenames all use sufficient leading zeros:
D = '.'; % absolute or relative path to where the files are saved.
S = dir(fullfile(D,'*.mat'));
N = numel(S);
for k = 1:N
F = fullfile(D,S(k).name);
T = load(F);
S(k).data = T.data_matrix;
end
A = cat(3,S.data);
size(A)
ans = 1×3
2048 22 4

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by