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

13 vues (au cours des 30 derniers jours)
Roger
Roger le 17 Mar 2014
Commenté : Walter Roberson le 17 Mar 2014
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?

Réponse acceptée

Jos (10584)
Jos (10584) le 17 Mar 2014
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]

Plus de réponses (1)

Roger
Roger le 17 Mar 2014
is there a way like dictionary in struct
  1 commentaire
Walter Roberson
Walter Roberson le 17 Mar 2014
[tf, k] = ismember('GYA', station.name);
if tf
disp(station.Jingdu(k))
else
disp('no match')
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by