
カテゴリカル配列を X 軸データに使った棒グラフを bar 関数で描画すると、削除したはずのデータが表示されるのはなぜですか?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 3 Mar 2022
Réponse apportée : MathWorks Support Team
le 3 Mar 2022
bar 関数を使った棒グラフを作成しています。
Y軸のデータには NaN (欠損値)を含むデータがあるため、isnan 関数を使用してあらかじめ取り除いているのですが、X 軸データにカテゴリカル配列(categorical array) を使用していると、空のビンとしてグラフに表示されてしまいます。
%% サンプルデータ定義
x = categorical(1:5);
y = [1 2 NaN 5 10];
%% グラフィックス作成
figure
ind = ~isnan(y); % NaN を含むインデックスを検出
bar(x(ind),y(ind)) % 棒グラフ作成

Réponse acceptée
MathWorks Support Team
le 3 Mar 2022
これは横軸(X 軸)にカテゴリカル配列を使用しているためです。
NaN を含む列を削除しても、カテゴリの種類としては "3" も含まれています。
>> categories(x(ind))
ans =
5×1 の cell 配列
{'1'}
{'2'}
{'3'}
{'4'}
{'5'}
空のカテゴリを削除するためには、removecats 関数を使用します。
>> bar(removecats(x(ind)),y(ind))

0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur データ分布プロット dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!