Delete a line from a struct

62 visualizaciones (últimos 30 días)
José Pereira
José Pereira el 9 de Dic. de 2017
Comentada: Image Analyst el 9 de En. de 2020
Hi, i have a structure with 9 lines and 4 fields. How can i delete line 4?

Respuestas (2)

Image Analyst
Image Analyst el 9 de Dic. de 2017
To remove a field from a structure use rmfield(). For example if the structure is called mystruct and has fields field1, field2, field3, and field4
mystruct.field1 = rand();
mystruct.field2 = rand();
mystruct.field3 = rand();
mystruct.field4 = rand();
and you want to remove the field named "field4" you can do
mystruct = rmfield(mystruct, 'field4');
Structures don't have lines, unless what you mean is that a specification of a line (like a vector of points, or a slope and intercept) are stored in a field.

MeLearningProgramming
MeLearningProgramming el 9 de En. de 2020
structures can have lines: if you have
mystruct(1).field1 = rand();
mystruct(1).field2 = rand();
mystruct(1).field3 = rand();
mystruct(1).field4 = rand();
... till
mystruct(9).field1 = rand();
mystruct(9).field2 = rand();
mystruct(9).field3 = rand();
mystruct(9).field4 = rand();
you can remove a line like this:
mystruct(4) = [];
  1 comentario
Image Analyst
Image Analyst el 9 de En. de 2020
Well that would be very non-standard terminology. You've showed a structure array, or vector since it's 1-dimensional. It's a vector where each element is a structure. And each structure in the array is an element of the vector. I've never heard anyone call it a line. For example, with a double vector = [1,2,3,4,5], I've never heard someone call the 4th element a "line" instead. But maybe that's what the original poster meant.

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by