필터 지우기
필터 지우기

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

조회 수: 13 (최근 30일)
katha_lala
katha_lala 2018년 4월 19일
편집: KSSV 2018년 4월 19일

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!

채택된 답변

KSSV
KSSV 2018년 4월 19일
편집: KSSV 2018년 4월 19일
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

추가 답변 (0개)

카테고리

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