MATLAB Answers

plot with input arguments

1 view (last 30 days)
i want to subplot 4 string containg cell array from ( sin, cos, tan,sinh) and vector (+,o,*,x,s) and the mathmatical function should be ploted in interval (-2pi,2pi)with step 0.3

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Dec 2019
funs_cell = {'sin', 'cos', 'tan', 'sinh'};
markers = {'+', 'o', '*', 'x', 's'};
funs = cellfun(@str2fun, funs_cell, 'uniform', 0);
for K = 1 : length(funs)
plot(x, funs{K}(x), markers{K}, 'DisplayName', funs_cell{K});
hold on
end

  33 Comments

Walter Roberson
Walter Roberson on 11 Dec 2019
In MATLAB,
if numel(fun_cell)||numel(color)~=4 Error(msg)
would be interpreted as
if (numel(fun_cell) ~= 0) || (numel(color) ~= 4)
error(msg)
end
MATLAB itself has absolutely no transitive operators of the form
expression1 operator1 expression2 operator2 value
being intepreted as
(expression1 operator2 value) operator1 (expression2 operator2 value)
In MATLAB you need to be explicit,
if numel(fun_cell) ~= 4 || numel(color) ~= 4
error(msg)
end
Roger Nadal
Roger Nadal on 11 Dec 2019
If I don’t want to generate random order for then should I remove randperm?

Sign in to comment.

More Answers (0)

Sign in to answer this question.