how can i store the location (x,y) in a variable in a loop?

1 Ansicht (letzte 30 Tage)
angel
angel am 5 Mai 2013
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...

Akzeptierte Antwort

Youssef  Khmou
Youssef Khmou am 5 Mai 2013
Bearbeitet: Youssef Khmou am 5 Mai 2013
hi,
According to your program try this :
%BmatRows=140;
%BmatCols=150;
%blockSizeR=4;
%blockSizeC=5;
%incrR=1;
%incrC=1;
%rows=40;
%columns=40;
% THE VALUES ABOV ARE CREATED FOR TESTING PURPOSE
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;
TRACKING(index,:)=[rowStart colStart];
colEnd=col+(blockSizeC-1);
oneBlock=grayImage(rowStart:rowEnd,colStart:colEnd);
vecOneBlock= reshape(oneBlock,1,numel(oneBlock));
B(index,:)=vecOneBlock;
index=index+1;
end
end

Weitere Antworten (1)

Image Analyst
Image Analyst am 5 Mai 2013
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 Kommentare
Image Analyst
Image Analyst am 5 Mai 2013
Sorry - forgot that starts was a 2D array and needs 2 indexes. Try it this way:
starts=starts(sortingIndex, :);
angel
angel am 6 Mai 2013
it works thank you so much sir

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by