Creating a bar plot from a categorical subarray

9 ビュー (過去 30 日間)
Leonard Koch
Leonard Koch 2021 年 1 月 3 日
コメント済み: Leonard Koch 2021 年 1 月 6 日
Dear all, i am trying to plot my measured data against a categorical array. In my script i used 'sample1' as a categorical array that contains a portion of 'samples', which contains all sample names.
(The same goes for 'rq1' which contains the corresponding values to the measured samples extracted from 'rq')
I extract sample1 out of samples via
sample1 = categorical(samples(7:10))
which correctly produces this output:
sample1 = 1×3 categorical array
Ctrl male Ctrl female 13_0551
when I bar plot the 'sample1' values against 'rq1', it produces an output that contains all the content from 'samples' on the x-axis, and not just 'sample1'
bar(sample1, rq1)
however, manually creating a categorical array 'test' that contains the same items using
test = categorical({'Ctrl male' 'Ctrl female' '13_0551'})
and plotting against 'rq1 results in (almost) the desired output, but obviously I dont want to write down every item out of the original list with 72 items.
bar(test, rq1)
is there a way to work around this problem?
full code is:
sample1 = categorical(samples(7:10))
rq1 = rq(7:10)
test = categorical({'Ctrl male' 'Ctrl female' '13_0551'})
bar(sample1, rq1)
%bar(test, rq1)

採用された回答

Adam Danz
Adam Danz 2021 年 1 月 3 日
編集済み: Adam Danz 2021 年 1 月 5 日
idx = 7:10;
bar(categorical(samples(idx)), rq(idx))
If you want to eliminate categories with a bar height of 0,
idx = rq~=0;
  1 件のコメント
Leonard Koch
Leonard Koch 2021 年 1 月 6 日
Thank you! I eventually used code a bit different but working with the same principle

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCategorical Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by