MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。

ELCIO S
0

How to dynamically name each box on a boxplot?

ELCIO S
さんによって質問されました 2019 年 4 月 23 日
最新アクティビティ ELCIO S
さんによって コメントされました 2019 年 5 月 22 日
Hi! I have a struct file, in this, there are some data (see 'data.mat'). I need to make a boxplot with this. But I dont know how to use the fields name of the boxplot to put it in the boxplot figure. Can anyone help me?
Let me make it clear. In the data, there are many possible combinations who I need to compare in groups. In this way, I need, for example, see what is the effect of the parameter "b" in my results. So, for example, I need to compare the boxplot of 'data.a1.b1.c1.mem' with 'data.a1.b2.c1.mem', 'data.a1.b3.c1.mem' and 'data.a1.b4.c1.mem'. I wanna know how to put, dinamically, a1, b* and c1 in corresponding boxplot for future references, in other words, in the figure below, where I have 1, 2, 3 and 4, I need to put something like a1b1c1, a1b2c1, a1b3c1 and a1b4c1 respectively in a dynamic way.
untitled.jpg
How can I do it?
Thank you!

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Adam Danz
2019 年 4 月 23 日
編集済み: Adam Danz
2019 年 5 月 21 日
 採用された回答

You can convert the nested field names into a string using this FEX submission: fieldnamesr()
Then you can use those strings as your XTickLabels.
Here's some code that demonstrates this - you can adapt it to your needs. The demo produces a boxplot figure with nested field names as x labels.
data.a1.b1.c1 = nan;
data.a1.b2.c1 = nan;
data.a1.b3.c1 = nan;
data.a1.b4.c1 = nan;
% Get all field names
fields = fieldnamesr(data, '-full');
xLabels = strrep(fields, '.', '');
boxplot(randi(100,1,1000), randi(4,1,1000))
set(gca, 'XTickLabels', xLabels)
190521 085358-Figure 1.jpg

  1 件のコメント

ELCIO S
2019 年 5 月 22 日
Thank you! It works!

サインイン to comment.



Translated by