converting multiple file of 4D to 3D files

1 回表示 (過去 30 日間)
Hanisah noh
Hanisah noh 2020 年 7 月 3 日
コメント済み: Hanisah noh 2020 年 7 月 10 日
i have 80 files of 4D double (140x122x180x#)
i need the files in 3D (140x122x180)
i have tried these solutions but does not come out as expected
files = B % 140x122x180x#
threeD = permute(files[1,2,3,4])
% the result will be 4D double
% i also tried
threeD = squeeze(num2cell(permute(files,[1,2,3,4]),1:3))
% the result will be #x1 cells
current coding :
cd ('path');
files=dir('*.mat'); % find all |.mat| files in the current directory.
totalfile = numel(files); % count those files.
C = cell(1,totalfile); % preallocate a cell array for the loaded data.
for a = 1:totalfile % loop over the number of files.
T = load(files(a).name) % load the data from each file
C(a) = struct2cell(T); % convert structure to cell, allocate to cell array.
M = cat(4,C{:}) % concatenate all MxN matrices into MxNxP array,
% 3 dimensional concatenate
% ???
save(['path/zscore_' num2str(a) '.mat'],'M');
end
thank you
  4 件のコメント
Rik
Rik 2020 年 7 月 3 日
I don't know what your variables mean, they're your variables.
The 2 is just an example, as you didn't secribe what value # should have. You wanted a length of 1 in the fourth dimension, that is what this code does. It selects the second book. (in general the first 2 dimensions of an array are called rows and columns, the third is often called page, and some people call the fourth dimension book (i.e. a collection of pages))
Hanisah noh
Hanisah noh 2020 年 7 月 3 日
i see. thanks ! big help

サインインしてコメントする。

採用された回答

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020 年 7 月 5 日
Hey Hanisah,
As mentioned by @Rik, iterate through the collection of 4D matrices to get your 3D values.
For example,
for i = 1:size(B, 4)
A = B(:,:,:,i) % Simple example to slice your 4D matrices
end
Hope this helps!
  1 件のコメント
Hanisah noh
Hanisah noh 2020 年 7 月 10 日
thank you. this helps 👍

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by