Effacer les filtres
Effacer les filtres

Select structure fields with certain name and put it into new variable

13 vues (au cours des 30 derniers jours)
katha_lala
katha_lala le 19 Avr 2018
Modifié(e) : KSSV le 19 Avr 2018

Hello everyone,

let's say I have a structure called "delta" with double-numbers in it and it is structured as follows:

 delta.SF_SVDC
 delta.SF_SVDF
 delta.SF_MFD
 delta.SF_MFN

How can I manage to extract only the structure fields that f.ex. contain the word "SVDC" in it with their content into a new variable (let's call it 'SVDC' then)?

I tried something with

 names=fieldnames(delta);
 TF=contains(names,'SVDC');
 if TF==1 ...

... and then I am lost.

Help is greatly appreciated! Thanks!

Réponse acceptée

KSSV
KSSV le 19 Avr 2018
Modifié(e) : KSSV le 19 Avr 2018
delta.SF_SVDC = rand ;
 delta.SF_SVDF  = rand ;
 delta.SF_MFD  = rand ;
 delta.SF_MFN  = rand ;
   names=fieldnames(delta);
   TF=contains(names,'SVDC');
   if any(TF)
      value = getfield(delta,names{TF})
   end

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by