0
votes

I have a struct array field seg.startscan. I want to erase some of its elements.

For example the elements corresponding to the indices stored contained in an array INDS.

The followings are ny try and the relative errors:

1)

seg.startscan(INDS) = [ ];

??? Scalar structure required for this assignment.

2)

seg(INDS).startscan = [ ];

??? Insufficient outputs from right hand side to satisfy comma separated list expansion on left hand side. Missing [] are the most likely cause.

3)

startscans = seg.startscan; startscans(INDS) = [ ]; fldnm = 'startscan'; seg.(fldnm) = startscans;

??? Insufficient outputs from right hand side to satisfy comma separated list expansion on left hand side. Missing [] are the most likely cause.

4)

startscans = seg.startscan; startscans(INDS) = [ ]; fldnm = 'startscan'; [seg.(fldnm)] = startscans;

??? Too many output arguments.

5) as suggested here: 1:

>>startscans = seg.startscan;
startscans(INDS) = [ ];
fldnm = 'startscan';
[seg.(fldnm)] = startscans;

??? Too many output arguments.

Do you have any ideas? Probably I do not grasp the idea behind the struct arrays..

Let's say that my input is:

>>seg.startscan
ans=
1
ans=
2
ans=
3
ans=
4
>>INDS = [1 3];

then my expected output is:

>>seg.startscan 

ans=
2
ans=
4

This gave a quite similar solution, but it not vectorized and not completely right

 >>for i = 1:numel(INDS)
    seg(IND(i)).startscan=[];
 end
 >>seg.startscan 

ans=
[]
ans=
2
ans=
[]
ans=
4

Help please!

Thank you!

1
You can't erase a field for some of the indices. You can erase the whole records indicated by INDS, with all their fields. Does the struct array have more fields other than startscan?Luis Mendo
Yes. It also has a seg.stopscanshamalaia
You can't have for example seg(1) with only field startscan and seg(1) with fields startscan and stopscan. You need to delete all fields of seg(1). Or fill with empty: either seg(1).startscan = []; or [seg(IND).startscan] = deal([])Luis Mendo
@A_C: It seems you are trying something impossible. Could you put your input and your expected output in valid matlab syntax into your question? If you fail to do so, the expected output is probably not a valid data structure.Daniel
@Daniel good call on inputs/output... was a simpler problem than (i assume) we all thoughtRTL

1 Answers

2
votes

To transform

seg.startscan = [1 2 3 4 5]; INDS = [1 3];

into

seg.startscan = [2 4 5];

you simply use

seg.startscan(INDS) = [];