different z values for one x y coordinate
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Sean de Wolski
2012년 3월 7일
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
Markus
2012년 3월 7일
Sean de Wolski
2012년 3월 7일
yes, accumarray with unique and mean() would be ideal. Though a for-loop works well too!
Markus
2012년 3월 7일
Sean de Wolski
2012년 3월 7일
Sure. I'll never turn down any opportunity to use accumarray (or bsxfun)!
Markus
2012년 3월 8일
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!