Keep selected rows in a struct file

12 visualizzazioni (ultimi 30 giorni)
SChow
SChow il 20 Mag 2021
Modificato: SChow il 20 Mag 2021
Hello,
I have a 600x1 struct file with 5 fields. One of the field is 'labels', containing random numbers from 1 to 1000. and a separate array (jn) 1x 500 containg 500 integers.
I am trying to remove the rows in the struct file with 'labels' which do not match the integers in the 'labels' array.
The solutions already on internet does not seem to work for me.
Thanks
I tried the following, where S is the struct and jn is the array
jn=num2cell(jn);
idx = ismember({S.labels}', jn);
Sx = S(idx);
The following error appears
Error using cell/ismember (line 34)
Input A of class cell and input B of class char must be cell arrays of character vectors, unless one is a character vector.
  4 Commenti
SChow
SChow il 20 Mag 2021
Modificato: SChow il 20 Mag 2021
Thanks!! Please find the attached .shp file.
loc_id in the shapefile(.shp) ~ labels
SChow
SChow il 20 Mag 2021
Modificato: SChow il 20 Mag 2021
Many thanks Stephen, I think that the issue is solved now!!

Accedi per commentare.

Risposta accettata

SChow
SChow il 20 Mag 2021
Modificato: SChow il 20 Mag 2021
%%jn is the array, (not converted to cell array that I was originally
%%converting it to , and I should have used square brackets instead of curly brackets)
idx = ismember([S.loc_id]', jn);
Sx = S(idx);

Più risposte (0)

Categorie

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

Community Treasure Hunt

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

Start Hunting!

Translated by