The variable mtx_pstn are the positions (i,j) of each element of a 4x6 matrix, and mtx_cord is a variable that stores a set of coordinates (or points if you wanna see it that way). I wanna count how many times there is a point with the same coordinates as the element position stored in mtx_pstn, that's why i use Lia_reps to make the scan, and after that i create pts_dsty_mod to count the repeated elements; but after counting, if there's more than one repetition of an element, it will just store a 1 instead of a 2 or 3, etc. so that's where im having trouble.
Also, the points stored in mtx_cord are randomly generated each time you run the script. I'd appreciate if you could help me out with this!
Lia_reps=ismember(mtx_pstn, mtx_cord, 'rows');
pts_dsty_mod=ones(size(grid_size)-1);
for i=(1:length(Lia_reps))
if Lia_reps(i) == 1
pts_dsty_mod(i)=pts_dsty_mod(i)+1;
else
pts_dsty_mod(i)=pts_dsty_mod(i);
end
end
pts_dsty_mod=pts_dsty_mod-1
pts_dsty_mod =
0 0 0 1 1 1
0 0 0 1 0 1
0 0 1 0 0 1
0 0 0 0 0 1
2 Comments
Jan (view profile)
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/468933-i-need-to-make-a-matrix-count-a-given-set-of-repeated-elements-but-it-doesnt-work-at-all#comment_718401
Guillaume (view profile)
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/468933-i-need-to-make-a-matrix-count-a-given-set-of-repeated-elements-but-it-doesnt-work-at-all#comment_718419
Sign in to comment.