필터 지우기
필터 지우기

How to find unique values in a field of a nested struct

조회 수: 16 (최근 30일)
elisa ewin
elisa ewin 2017년 3월 30일
답변: KSSV 2017년 3월 30일
Hi,
I have a nested struct user.data (attached) anda I want to find the unique values of the field touristicRoute (user.data.touristicRoute)
I have tried this code:
for m=1:size(Cluster_USERS,1)
for i=1:size(userTouristicTraj(m).touristicData,2)
if (user(m).data(i).touristicRoute~=0)
uniqueValues=unique(user(m).data(i).touristicRoute)
end
end
end
but it doesn't give me the right value, can you help me?
  댓글 수: 1
Jan
Jan 2017년 3월 30일
What is "the right value"? The posted code does give you "unique values of the field touristicRoute". Or do you get an error message? Please explain exactly, what you need.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2017년 3월 30일
load matlab.mat
N = length(user) ;
iwant = cell(N,1) ;
for i = 1:N
M = length(user(i).data) ;
val = cell(M,1) ;
for j = 1:M
val{j} = user(i).data(j).touristicRoute ;
end
val = cell2mat(val) ;
iwant{i} = unique(val) ;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by