Delete a line from a struct
61 次查看(过去 30 天)
显示 更早的评论
Hi, i have a structure with 9 lines and 4 fields. How can i delete line 4?
0 个评论
回答(2 个)
Image Analyst
2017-12-9
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.
0 个评论
MeLearningProgramming
2020-1-9
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 个评论
Image Analyst
2020-1-9
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!