Filter löschen
Filter löschen

how convert string in struct with 0/1

1 Ansicht (letzte 30 Tage)
aldo
aldo am 3 Nov. 2023
Beantwortet: Stephen23 am 3 Nov. 2023
>> class(Sis)
ans =
'struct'
>> size(Sis)
ans =
1 351
i access it using : Sis(1).FilterSkip
Sis.FilterSkip can to be "No" or "Si" or "Rank"
if Sis.FilterSkip ="No" i want to get 0.
.if Sis.FilterSkip="Si" i want to get 1
i want to create vector wih 0 or 1 using Sis.FilterSkip
  2 Kommentare
Dyuman Joshi
Dyuman Joshi am 3 Nov. 2023
What should be the value when Sis.FilterSkip is "Rank"?
aldo
aldo am 3 Nov. 2023
if it's "Rank" ignore value

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 3 Nov. 2023
S = struct('FS',{'Si','No','Si','Rank','No'})
S = 1×5 struct array with fields:
FS
Z = nan(size(S));
[X,Y] = ismember({S.FS},{'No','Si'});
Z(X) = Y(X)-1
Z = 1×5
1 0 1 NaN 0

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by