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

Réponses (4)

Walter Roberson
Walter Roberson le 9 Mar 2011

1 vote

No, there isn't. Please read the FAQ for better alternatives.
the cyclist
the cyclist le 9 Mar 2011

0 votes

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 le 9 Mar 2011

0 votes

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 le 9 Mar 2011

0 votes

Thanks, I'll look up cell arrays

Catégories

En savoir plus sur Denoising and Compression dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by