Can anyone debug this code? Confusion with cell array

3 visualizaciones (últimos 30 días)
Jab
Jab el 13 de Sept. de 2015
Comentada: Jab el 13 de Sept. de 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..

Respuesta aceptada

Stephen23
Stephen23 el 13 de Sept. de 2015
Editada: Stephen23 el 13 de Sept. de 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.

Más respuestas (0)

Categorías

Más información sobre Discrete Multiresolution Analysis en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by