converting multiple file of 4D to 3D files

1 vue (au cours des 30 derniers jours)
Hanisah noh
Hanisah noh le 3 Juil 2020
Commenté : Hanisah noh le 10 Juil 2020
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 commentaires
Rik
Rik le 3 Juil 2020
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 le 3 Juil 2020
i see. thanks ! big help

Connectez-vous pour commenter.

Réponse acceptée

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi le 5 Juil 2020
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 commentaire
Hanisah noh
Hanisah noh le 10 Juil 2020
thank you. this helps 👍

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by