Plot a struct field that is an array of doubles

I have data stored in a struct with fields 'BO' and 'tota' which I want to plot something like:
plot([data.BO], [data.tota])
but the problem is that each element of the 'tota' field is an array. I want to plot all of the array as multiple y values for the single x value. Example data structure and plot below (plotting was accomplished by breaking the single struct into multiple standalone matrix).
In truth, I want to do something like:
figure; hold on;
plot([data.BO],[data.tota(:,1:end-2)],'o')
plot([data.BO],[data.tota(:,end-1)])
plot([data.BO],[data.tota(:,end)])
The best I can do is
b = cell2mat({data.tota}');
plot([data.BO],b(:,1:end-2),'o')
...
But I was wondering if there is a more elegant way to plot directly from the struct without needing to duplicate data into a bunch of temporary variables.

 採用された回答

Matt J
Matt J 2023 年 10 月 5 日
編集済み: Matt J 2023 年 10 月 5 日

0 投票

plot([data.BO], vertcat(data.tota),'o')

2 件のコメント

Brett Wingad
Brett Wingad 2023 年 10 月 5 日
Thanks!, that should have been obvious. There is no way (without saving off to a new variable) to easily index in and limit the plotting to only a subset of the columns?
Matt J
Matt J 2023 年 10 月 5 日
Thanks!
You're quite welcome. Please Accept-click the answer if it fulfills what you were looking for
There is no way (without saving off to a new variable) to easily index in and limit the plotting to only a subset of the columns?
No, but you can easily suppress certain lines after the fact, e.g.,
data=rand(10,4);
H=plot(data,'-o');
[H(1:2).Visible]=deal('off'); %suppress first 2 lines

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2023a

質問済み:

2023 年 10 月 5 日

編集済み:

2023 年 10 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by