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

8 次查看(过去 30 天)
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

类别

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