How to plot x-y coordinates which correspond to elements which are repeated at least once
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
My project concerns capture & recapture of rats. I have a 1040 x 3 array, the first column is the tag number of the rat (when each rat is captured for the first time, its given a tag (harmlessly of course!) the other 2 columns are the x & y coordinates respectively of where in a 7x7 plane the rat was captured. If the same rat is captured again, its position is then recorded again. I want to plot how the position of all of the individual rats which were captured more than once change over time. I've got a list of the indices of all of the non-repeated elements (i.e. all the rats which were seen once, but not again), but don't know where to go from there. Thanks for any help
3 Kommentare
Akzeptierte Antwort
John Petersen
am 29 Nov. 2012
This may get you started
A = 1040x3 array
[r,c] = size(A);
[tags, iA,ic] = unique(A(:,1)); % rats that have been captured
t = 1:r; % scale time as needed.
rat2 = setdiff(tags,iA); % rats that have been captured more than once
colr = ['b','g','r','m','c','k']; % identify rats with different colors
figure;
for i=1:length(rat2)
ind = A(:,1)==A(rat2(i),1); % pick all the rat locs for rat i
plot3(t(ind),A(ind,2),A(ind,3),colr(i)); % plot rat i trajectory
hold on;
end
grid on;
9 Kommentare
John Petersen
am 5 Dez. 2012
The dimensions I was user were, time, x, and y. But if all you want is x,y, then try what I have below. I also fixed the last little problem I think.
TAGS = [1:6]';
A = [ TAGS(ceil(6*rand(20,1))) rand(20,2)];
[r,c] = size(A);
[tags, iA,ic] = unique(A(:,1)); % rats that have been captured
t = [1:r]'; % scale time as needed.
niA = setdiff(t,iA);
[rat2,i2] = intersect(A(niA,1),A(iA,1)); % rats that have been captured more than once
rat2ind = [iA;niA(i2)]; % indices of rats seen 2+ times
colr = ['bo-';'go-';'ro-';'mo-';'co-';'ko-']; % identify rats with different colors
figure;
for i=1:length(rat2)
ind = A(:,1)==rat2(i); % pick all the rat locs for rat i
plot(A(ind,2),A(ind,3),colr(i,:)); % plot rat i trajectory
hold on;
end
Weitere Antworten (1)
Timothy Russell
am 27 Jan. 2013
2 Kommentare
John Petersen
am 29 Jan. 2013
Isn't "A" the nx3 matrix you're looking for? or am I missing something?
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms 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!