legend NumColumns not working in 2018a

38 ビュー (過去 30 日間)
Phil
Phil 2021 年 9 月 16 日
コメント済み: Phil 2021 年 9 月 17 日
I'm using MATLAB 2018a, which I understand is when the NumColumns property of legend appeared. But when I run this code:
t = 2*pi*(0:0.01:1);
x1 = sin(t);
x2 = cos(t);
figure(1)
plot(t,x1)
hold %on
plot(t,x2)
hold %off
xlim([0 2*pi])
legend('sin(t)','cos(t)','NumColumns',2)
I receive these errors:
Error using legend>process_inputs (line 554)
Invalid argument. Type 'help legend' for more information.
Error in legend>make_legend (line 306)
[autoupdate,orient,location,position,children,listen,strings,propargs] = process_inputs(ha,argin);
%#ok
Error in legend (line 259)
make_legend(ha,args(arg:end),version);

採用された回答

the cyclist
the cyclist 2021 年 9 月 16 日
It looks to me that the documentation states the change was in R2018b, not R2018a.
As you can see, that code works fine here (R2021a):
t = 2*pi*(0:0.01:1);
x1 = sin(t);
x2 = cos(t);
figure(1)
plot(t,x1)
hold %on
Current plot held
plot(t,x2)
hold %off
Current plot released
xlim([0 2*pi])
legend('sin(t)','cos(t)','NumColumns',2)
  4 件のコメント
the cyclist
the cyclist 2021 年 9 月 17 日
編集済み: the cyclist 2021 年 9 月 17 日
I was looking at "Compatibility Considerations" ("legend interprets arguments as property names when property exists") in the documentation for legend.
Frankly, your reference seems to more definitively argue that this functionality should be there in R2018a. ¯\_(ツ)_/¯
(But @Steven Lord's comment is spot-on, I think.)
Phil
Phil 2021 年 9 月 17 日
@Steven Lord Ah, that's it! NumColumns works in R2018a if I use a Legend object as you suggested. Thanks so much!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by