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

2 次查看(过去 30 天)
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