figureの座標データ取得について

プロット図上の複数のデータを選択し,座標データを取得したいと思います。
5個のデータを選択して上のようなstructを取得することはできました。
ここから以下のように1列目のデータの小さい順にPositionのデータのcellを作りたいです。
このようにstructののものをcellに変換する方法がよくわかっておりません。初歩的な質問で申し訳ないですが、いい方法を教えてくださいませんでしょうか。

 Accepted Answer

Naoya
Naoya on 14 Mar 2022

0 votes

あくまでも一例となると思いますが、以下のように 構造体配列の各要素に特定の処理を適用することができる arrayfun関数を使うと比較的スマートに処理することができると思われます。
% DataIndex に対して昇順にソートする (ここでは配列要素順を取得)
[~,idx] = sort( arrayfun(@(x) x.DataIndex,cursor_info) );
% DataIndex と Position の 2要素目を取得
celldata = arrayfun(@(x) [x.DataIndex, x.Position(2)], cursor_info(idx)', 'UniformOutput', false);
% セル配列から通常の行列に変換
matdata = cell2mat(celldata);

1 Comment

ryu
ryu on 15 Mar 2022
丁寧な説明ありがとうございました!

Sign in to comment.

More Answers (0)

Categories

Asked:

ryu
on 10 Mar 2022

Commented:

ryu
on 15 Mar 2022

Community Treasure Hunt

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

Start Hunting!