Plot Multiple Functions in a single call to fplot
Ältere Kommentare anzeigen
I want to draw 2 concentric circles using fplot. Suppose that radius of 1st circle is 1 and 2nd circle is 0.8 then
For Loop Method
f = figure;
ax =axes(f);
y = [1 0.8];
for i=1:2
xt = @(x) y(i)*cosd(x);
yt = @(x) y(i)*sind(x);
fplot(ax,xt,yt,[0 360])
end

Direct Method
Now instead of applying for loop, add two functions in xt and two in yt as shown below
xt = {@(x) cosd(x);@(x) 0.8*cosd(x)};
yt = {@(x) sind(x);@(x) 0.8*sind(x)};
Now if i use fplot
fplot(xt,yt,[0 360])
Following error occured

This error will not occur for fplot(xt,yt{1},[0 360])
I opened fplot function and i think this line is causing problem (line 69-72)
if ~isempty(args) && (isa(args{1},'function_handle') || isa(args{1}, 'sym'))
fn{end+1} = args(1);
args(1) = [];
end
Note that before these lines the first argument (i.e. xt) is passed to fn and removed from args which means that now args(1) means the 2nd argument (i.e. yt)
Now the problem is that args{1} is a cell containing two functions.
isa(args{1},'function_handle')
returns logic 0 because
args{1}
ans =
2×1 cell array
{ @(x)sind(x)}
{@(x)0.8*sind(x)}
instead of args{1} there must be condition which check every element of args{1}{1,2,...}
isa(args{1}{1},'function_handle') % or 2 (equal to length of args{1}
Now i suppose that somehow this condition is true and we are on next line
fn{end+1} = args(1);
there should be an iscell condition here and if it is true the code should be
fn{end+1} = args{1};
Now if i make only these 2 corrections fplot works perfectly because at line 166
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);
has no problem with it
Long story short,
- how to add changes in fplot code (as it is a static workspace and i dont know if it is allowed to edit them)
- is this issue resolved in future release
Regards,
M.Saad
Akzeptierte Antwort
Weitere Antworten (1)
madhan ravi
am 4 Jun. 2020
2 Stimmen
Long story short , it's not possible to use fplot(...) in a single call.
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!