Filter löschen
Filter löschen

different z values for one x y coordinate

5 Ansichten (letzte 30 Tage)
Markus
Markus am 7 Mär. 2012
hei,
my problem is, that i have xyz points and it happens, that for one identical x,y value i get several z values.
now i want to get all z values for one x,y koordinate.
i tried first with unique so i now all x,y koordiates. but now i would like to get all z values which belong to this x,y.
thanks for help. ;-) markus

Akzeptierte Antwort

Markus
Markus am 7 Mär. 2012
%%looking for unique xy values
uniCoord=unique(data(:,1:2),'rows');
uniCoord(:,3:12)=NaN;
%%writing for each xy value in column
% 3-9 all corresponding z values
% 10 amount of corresponding z values
% 11 median of z values
% 12 mean of z values
for i =1:size(uniCoord,1)
A=(data(:,1)==uniCoord(i,1)&data(:,2)==uniCoord(i,2));
B=data(A,3)';
uniCoord(i,3:2+size(B,2))=B;
uniCoord(i,10)=size(B,2);
uniCoord(i,11)=median(uniCoord(i,3:2+size(B,2)));
uniCoord(i,12)=mean(uniCoord(i,3:2+size(B,2)));
end

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 7 Mär. 2012
You could use the index output arguments of unique along with accumarray(). What do you want to do with multiple z values?
doc unique %look at 3rd output
doc accumarray
More per comments:
xy = [1 2; 1 2; 1 2; 3 4; 5 6; 5 6; 7 8]; %xy pairs
z = (1:length(xy))';
[~,idxk,idxn] = unique(xy,'rows'); %idxk = kept rows, idxn = subs_rows
zmean = accumarray(idxn,z,[],@mean); %get the mean of the groups
xyz = [xy(idxk,:) zmean] %concatenate
  5 Kommentare
Sean de Wolski
Sean de Wolski am 7 Mär. 2012
Sure. I'll never turn down any opportunity to use accumarray (or bsxfun)!
Markus
Markus am 8 Mär. 2012
ok. thats a nice solution thanks. :)

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by