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!