Effacer les filtres
Effacer les filtres

Delete a line from a struct

96 vues (au cours des 30 derniers jours)
José Pereira
José Pereira le 9 Déc 2017
Commenté : Image Analyst le 9 Jan 2020
Hi, i have a structure with 9 lines and 4 fields. How can i delete line 4?

Réponses (2)

Image Analyst
Image Analyst le 9 Déc 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 le 9 Jan 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 commentaire
Image Analyst
Image Analyst le 9 Jan 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by