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
回答(4 个)
Walter Roberson
2011-3-9
1 个投票
the cyclist
2011-3-9
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
2011-3-9
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Denoising and Compression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!