How to inset an element into an ordered struct array?

10 ビュー (過去 30 日間)
Lucyanno Frota
Lucyanno Frota 2020 年 9 月 25 日
コメント済み: J. Alex Lee 2020 年 9 月 25 日
This link shows how to sort an struct array by a certain field: https://stackoverflow.com/questions/25047590/sorting-array-of-objects-by-property-in-matlab
Using this method every time I need to insert a new element I have to insert the element in a arbitrary position and sort it again.
I want to insert the element directly in the correct position. Matlab already have a way to achieve this? Or I need to implement it?
  2 件のコメント
J. Alex Lee
J. Alex Lee 2020 年 9 月 25 日
if you're worried about having the implement the insert+sort every time, you can package that into a method of the class (and even overload "sort"). Stijn's link will help if you already know which index you want to insert into, but if you don't know then you can't avoid the sort either before or after - in which case might as well be after.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by