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);
if isfield(params, 'legend')
legend(params.legend);
end
if isfield(params, 'grid')
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 Comment
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/447487-error-using-grid-too-many-input-arguments#comment_676123
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/447487-error-using-grid-too-many-input-arguments#comment_676123
Sign in to comment.