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
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
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')
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
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!