Azzera filtri
Azzera filtri

split struct based on description

4 visualizzazioni (ultimi 30 giorni)
Alberto Acri
Alberto Acri il 15 Giu 2023
Modificato: Stephen23 il 15 Giu 2023
Hi. How do you subdivide the struct into multiple structs as shown in the figure?

Risposta accettata

Stephen23
Stephen23 il 15 Giu 2023
C = {S.SeriesDescription};
S_scout = S(strcmpi(C,'Scout'))
S_serie = S(strcmpi(C,'Serie'))
S_stand = S(strcmpi(C,'Standard'))
If you want to do it "automatically" for multiple different strings:
Note that splitting up data is rarely a good approach to processing data. Usually keeping data together makes it easier to process.
  2 Commenti
Alberto Acri
Alberto Acri il 15 Giu 2023
How can I do it if I want to directly use the names in the cell and create the substructures simultaneously?
C = {S.SeriesDescription};
myCell = {'Scout'; 'Serie'; 'Standard'};
K=1;
name_1 = myCell{K,1};
S_1 = S(strcmpi(C,name_1));
Stephen23
Stephen23 il 15 Giu 2023
Modificato: Stephen23 il 15 Giu 2023
"How can I do it if I want to directly use the names in the cell and create the substructures simultaneously?"
If you really want to force yourself into writing slow, complex, inefficient, obfuscated, buggy code that is harder to debug, you can find plenty of examples linked here:

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by