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

2 Ansichten (letzte 30 Tage)
college student
college student am 10 Jul. 2021
Kommentiert: Stephen23 am 11 Jul. 2021
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 Kommentare
Simon Chan
Simon Chan am 10 Jul. 2021
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 am 10 Jul. 2021
Bearbeitet: Stephen23 am 10 Jul. 2021
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).

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 10 Jul. 2021
Bearbeitet: Stephen23 am 10 Jul. 2021
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

Kategorien

Mehr zu Images 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