Trouble with for loop

Hi, I'm trying to implement the following code to split my image Lumfront into blocks and carry out haar wavelets on each block. The code below works but I'm wondering if there is an easy way to output all the values as C1,C2....Cblocksize and CA1,CA2,... CH1,CH2... etc
My code is: %% Start of main loop
blockend = blocksize - 1;
for i = 1:blocksize:(M - 1) for j = 1:blocksize:(N - 1)
C= Lumfront(i:i+blockend, j:j+blockend)
'Wavelet bands are:'
[CA, CH,CV,CD] = dwt2(C, 'haar') end end

Respuestas (4)

Walter Roberson
Walter Roberson el 9 de Mzo. de 2011

1 voto

No, there isn't. Please read the FAQ for better alternatives.
the cyclist
the cyclist el 9 de Mzo. de 2011

0 votos

It is bad to define multiple variables in this way. One simple alternative is to use cell arrays:
C{i}= Lumfront(i:i+blockend, j:j+blockend)
Note that those are curly brackets, not parentheses. (I suggest you read the documentation on cell arrays.)
Also, you might just be able to define C as a big array, with one column for each output. I can't tell for sure from what you have written, though.
Matt Fig
Matt Fig el 9 de Mzo. de 2011

0 votos

As others have suggested, this is not "trouble with a FOR loop," but trouble with the way you are approaching the problem. You are going to end up with many-many variables all of which need to be processed through the same clumsy (and slow!) methods which produced them in the first place. Instead use a cell array, either producing each element in a loop or using some built-in functions when possible.
Karen Rafferty
Karen Rafferty el 9 de Mzo. de 2011

0 votos

Thanks, I'll look up cell arrays

Categorías

Más información sobre Denoising and Compression en Centro de ayuda y File Exchange.

Preguntada:

el 9 de Mzo. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by