Error using grid. Too many input arguments.
古いコメントを表示
Hello !
I am writing because I am encountering some issues with Matlab 2018a.
I developped a custom function to quickly plot a graph. Here is my file "test.m" :
x = 1:1:100;
y = x.^3;
new_plot(x, y, 'x', 'y = x^2', struct('grid', 'on', 'legend', {'y = x^2', 'Location', 'NorthEast'}));
function new_plot(x, y, x_label, y_label, params)
if ~exist('params', 'var')
params = struct();
end
figure;
plot(x, y);
xlabel(x_label);
ylabel(y_label);
% légende
if isfield(params, 'legend') % si grilles ou non
legend(params.legend);
end
% grilles
if isfield(params, 'grid') % si grilles ou non
grid (params.grid);
end
end
But I am facing with a console error :
Error using disp
Too many input arguments.
Error in test (line 4)
new_plot(x, y, 'x', 'y = x^2', struct('grid', 'on', 'legend', {'y = x^2', 'Location', 'NorthEast'}));
I remark than this does work :
x = 1:1:100;
y = x.^3;
new_plot(x, y, 'x', 'y = x^2', struct('legend', {'y = x^2', 'Location', 'NorthEast'}));
So I can deduce ths problem is coming from my property "legend" of my struct "params".
Can you help me ?
1 件のコメント
Adam
2019 年 2 月 28 日
Using the debugger should help you locate the problem very quickly. In particular the Pause on errors (or Stop on errors in older versions) option which will land you on the line that is causing the error, from which you can use the callstack to navigate back up to your own code if it stops in the middle of the disp function.
採用された回答
その他の回答 (1 件)
Fangjun Jiang
2019 年 2 月 28 日
0 投票
params.grid has 3 'on' in it.
2 件のコメント
Robin L.
2019 年 2 月 28 日
Fangjun Jiang
2019 年 2 月 28 日
The cause is your usage of struct(). There are many ways to resolve this. The way you pass in your arguments is not typical. I am not sure what is your purpose. If you insist on a structure,
clear params
params.grid='on'
params.legend={'y = x^2', 'Location', 'NorthEast'};
plot(1:10);
grid(params.grid)
legend(params.legend{:})
カテゴリ
ヘルプ センター および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

