how can i store the location (x,y) in a variable in a loop?
이전 댓글 표시
the code i tried is:
index=1;
B=zeros(BmatRows,BmatCols);
for row=1:incrR:rows-(blockSizeR-1)
rowStart=row;
rowEnd=row+(blockSizeR-1);
for col=1:incrC:columns-(blockSizeC-1)
colStart=col;
colEnd=col+(blockSizeC-1);
oneBlock=grayImage(rowStart:rowEnd,colStart:colEnd);
vecOneBlock= reshape(oneBlock,1,numel(oneBlock));
B(index,:)=vecOneBlock;
index=index+1;
end
end
[B,index]=sortrows(B);
here i want to track the rowstart and colstart as a point location like (rowstart,colstart) stores in a variable and changed according to the loop after that.
the matrix B is now according to the "sortrows" function and the index is also according to the matrix B. i.e the "index" values also shuffles.
i want that the after storing point values in a variable it also shuffles according to the matrix B.
i dont know how to do this plz help me to do so...
채택된 답변
추가 답변 (1개)
Image Analyst
2013년 5월 5일
Inside the innermost loop, add these lines:
starts(index, 1) = rowStart;
starts(index, 2) = colStart;
Or as a single line like
starts(index, 1:2) = [rowStart, colStart];
댓글 수: 6
angel
2013년 5월 5일
Image Analyst
2013년 5월 5일
편집: Image Analyst
2013년 5월 5일
Is that really "oneBlock" instead of B, because after one row, B should have only one row, not 4.
And sortrows returns only 2 arguments, at most, not 3. And even if it did, you would totally trash the index and starts arrays that you took the trouble to create. Why would you do that?
Do you want this:
[B, sortingIndex] = sortrows(B);
% Re-order starts in the same way as B.
starts = starts(sortingIndex);
angel
2013년 5월 5일
angel
2013년 5월 5일
Image Analyst
2013년 5월 5일
Sorry - forgot that starts was a 2D array and needs 2 indexes. Try it this way:
starts=starts(sortingIndex, :);
angel
2013년 5월 6일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!