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

Stephen23
Stephen23 2021년 5월 20일
편집: Stephen23 2021년 5월 20일
What is a "struct file" ?
A file is data stored in non-volatile memory (e.g. a hard-drive).
A structure is a data type that exists in the MATLAB workspace.
It is not clear what a "struct file" could be. Please upload some sample data for us to work with.
SChow
SChow 2021년 5월 20일
Exactly, I have a file that is stored in hard drive. ie. S is a shape file. (.shp) that opens as structure in Matlab workspace
SChow
SChow 2021년 5월 20일
편집: SChow 2021년 5월 20일
Thanks!! Please find the attached .shp file.
loc_id in the shapefile(.shp) ~ labels
SChow
SChow 2021년 5월 20일
편집: SChow 2021년 5월 20일
Many thanks Stephen, I think that the issue is solved now!!

댓글을 달려면 로그인하십시오.

 채택된 답변

SChow
SChow 2021년 5월 20일
편집: SChow 2021년 5월 20일

0 개 추천

%%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);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2021년 5월 20일

편집:

2021년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by