How to skip the legends for some series of data that's actually Null after some Calculation?

1 回表示 (過去 30 日間)
Liwei Dai
Liwei Dai 2015 年 9 月 24 日
編集済み: Liwei Dai 2015 年 9 月 24 日
Hello, everyone. Here is the problem I am facing. Say I have 3 series of data, but some of the series could be of length 0. As I plotted them all on the same figure, I want to legend them correctly, how should I do that more compactly? Below is what I got ( notice the data are all in the structure Performance)
if cellfun('isempty', Performance.Apple)
legend('Orange', 'Banana');
elseif cellfun('isempty', Performance.Orange)
legend('Banana', 'Orange');
elseif cellfun('isempty', Performance.Banana)
legend('Apple', 'Orange');
elseif cellfun('isempty', Performance.Apple) & cellfun('isempty', Performance.Orange)
legend('Banana');
elseif cellfun('isempty', Performance.Apple) & cellfun('isempty', Performance.Banana)
legend('Orange');
elseif cellfun('isempty', Performance.Orange) & cellfun('isempty', Performance.Banana)
legend('Apple');
end
So you get what I'm trying to do, right? I know there must be a trick to do these smartly, please help me.

回答 (1 件)

Liwei Dai
Liwei Dai 2015 年 9 月 24 日
編集済み: Liwei Dai 2015 年 9 月 24 日
LegendVector = {'Apple', 'Orange', 'Banana'};
ActualLegend = [~cellfun('isempty', Performance.Apple),...
~cellfun('isempty', Performance.Orange), ...
~cellfun('isempty', Performance.Banana)];
LegendVector = LegendVector(ActualLegend);
legend(LegendVector);
This is by far what came to my mind, is there any other way to simplify the redundent cellfun in my code?

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by