Delete row from a structure array
79 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
For some reason, the solutions given on the internet don't seem to work for me. The most common solution I have seen is to just do what one would do for arrays. If 'a' is a structure array and I want to delete the 9th entry from all fields:
a(9)=[];
I get an error message saying "Matrix index is out of range for deletion."
What am I doing wrong? My strucutre array has both numeric and cell arrays. I tried removing the cell array field entirely and trying the above operation on the new array (which has only numeric fields), that didn't work either.
Thanks.
0 comentarios
Respuestas (1)
Matt J
el 13 de Sept. de 2015
Editada: Matt J
el 13 de Sept. de 2015
As far as can be seen, you simply aren't correctly assessing the number of elements in a. When a has 9 elements or more, as in the following example, things should work
>> clear a
>> a(20).numeric=123; a(20).cell={'dog','cat'}
a =
1x20 struct array with fields:
numeric
cell
>> a(9)=[]
a =
1x19 struct array with fields:
numeric
cell
2 comentarios
Walter Roberson
el 13 de Sept. de 2015
You might want to consider putting all of the numeric information together into one array, 6 x 53369 double, and accessing by rows when using the data. For example,
as_id = 1;
as_dtnum = 2;
as_lat = 3;
as_lon = 4;
as_sst = 5;
as_sss = 6;
ASSET.data(as_id,431) %equivalent to old ASSET.id(431)
and then you can delete all of the information for one asset by
ASSET.data(:,9) = [];
ASSET.type(9) = [];
(the cell needs to be maintained separately from the numeric values if you want easy numeric access to the numeric data.)
Ver también
Categorías
Más información sobre Data Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!