struct and cell ,is there a way like dictionary in struct

조회 수: 8 (최근 30일)
Roger
Roger 2014년 3월 17일
댓글: Walter Roberson 2014년 3월 17일
if true
end
station = struct(...
'name', {'CD2','GYA','LZH','GOM','XAN'},...
'Jingdu',{103.76 ,106.66,103.84,94.81,108.92},...
'Weidu',{30.91, 26.46, 36.09, 36.20, 34.03});
p={'CD2','GYA','LZH','GOM','XAN'};
now i pick one from p,how can i get the one 's Jingdu?

채택된 답변

Jos (10584)
Jos (10584) 2014년 3월 17일
You mean something like this?
station = struct(...
'name', {'CD2','GYA','LZH','GOM','XAN'},...
'Jingdu',{103.76 ,106.66,103.84,94.81,108.92},...
'Weidu',{30.91, 26.46, 36.09, 36.20, 34.03});
p={'CD2','GYA','LZH','GOM','XAN'};
K = 2 ; % pick one
TF = strcmp({station.name}, p{K}) % true when station.name equals p{K}
Result = [station(TF).Jingdu]

추가 답변 (1개)

Roger
Roger 2014년 3월 17일
is there a way like dictionary in struct
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 3월 17일
[tf, k] = ismember('GYA', station.name);
if tf
disp(station.Jingdu(k))
else
disp('no match')
end

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by