Effacer les filtres
Effacer les filtres

Can anyone debug this code? Confusion with cell array

2 vues (au cours des 30 derniers jours)
Jab
Jab le 13 Sep 2015
Commenté : Jab le 13 Sep 2015
I have little knowledge in Matlab. In the following code , for each value of i, the wavedec3 function returns 22 subbands and the feat_vect will return 20*1 vector. I am getting the output just for single i value. I am very much confused with cell array that how to provide result as M should contain {i}images inside each image, {22subbands} further inside the subbands of each,{20*1vector}
for i=1:3
%%%Read 3D volume struct:
n=volread(fullFileName{i});
%%%Read the 3D volume image
mri=n.img;
[Nx,Ny,Nz]=size(mri);
%3 Level 3DWT
w=wavedec3(mri,3,'haar');
%%%22 subbands
sb=w.dec;
while k<=length(sb)
%%%feature_vec returns 20*1 vector
[M{i}{k,1}]=feature_vec(sb{k,1});k=k+1;
end
end
Thanks for the help..
  2 commentaires
Jab
Jab le 13 Sep 2015
Thank you very much Stephen. Great idea..

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 13 Sep 2015
Modifié(e) : Stephen23 le 13 Sep 2015
Why do you need a cell array anyway? I would suggest that you store all of those vectors together in one numeric matrix. This has many advantages, particularly because many MATLAB operations can be performed on complete matrices (this is called code vectorization, and is the fastest and most efficient MATLAB code).
For this reason it is usually a good idea to keep your data together in numeric arrays as much as possible unless there is a very good reason to store them in cell arrays or structures. Learn to use the dimensions of numeric arrays rather than relying on cell arrays and suddenly you will find accessing and processing your data much simpler. Here is how that could work:
for m = 3:-1:1
%%%Read 3D volume struct:
S = volread(fullFileName{m});
%%%Read the 3D volume image
mri = S.img;
[Nx,Ny,Nz] = size(mri);
%%%3 Level 3DWT
W = wavedec3(mri,3,'haar');
%%%22 subbands
SB = W.dec;
for n = numel(sb):-1:1
%%%feature_vec returns 20*1 vector
M(:,n,m) = feature_vec(sb{n,1});
end
end
This will return a numeric matrix M with size 20*22*3, but you can play around with the index permuations of M to get the order that makes most sense to you or is most useful.
Note that I changed the name of the loop variables: i is the name of the imaginary unit and should be avoided.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Multiresolution Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by