using fimplicit function to plot

조회 수: 5 (최근 30일)
Maria Galle
Maria Galle 2020년 10월 2일
편집: John D'Errico 2020년 10월 2일
I'm trying to make a plot using the fimplicit function but the figure is empty.
zf(1) = figure(1);
za(1) = axes;
c = -4:2:4;
fimplicit(@(x,y) y.^2 - x.^2- c);

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 2일
For a single graph, c must be a scalar. If you want to plot the graph for all values in c, you can use for-loop or arrayfun() (kind of implicit for-loop)
zf(1) = figure(1);
za(1) = axes;
hold(za(1))
C = -4:2:4;
arrayfun(@(c) fimplicit(@(x,y) y.^2 - x.^2 - c), C);
  댓글 수: 2
Maria Galle
Maria Galle 2020년 10월 2일
How would I plot the graph for all values of c using a for loop? I tried writing the code but get the plot for one value of c.
for c=-4:2:4
zf(1) = figure(1);
za(1) = axes;
fimplicit(@(x,y) y.^2 - x.^2- c);
end
Ameer Hamza
Ameer Hamza 2020년 10월 2일
Move figure() and axes() out of for loop
zf(1) = figure(1);
za(1) = axes;
hold(za(1));
for c=-4:2:4
fimplicit(@(x,y) y.^2 - x.^2- c);
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2020년 10월 2일
편집: John D'Errico 2020년 10월 2일
As an alternative to the use of fimplicit, you can simply think of this as a contour plot. That is essentially all fimplicit does.
c = -4:2:4;
fxy = @(x,y) x.^2 - y.^2;
H = fcontour(fxy,[-5,5, -5,5],'LevelList',c);
Either way works. A contour plot has the virtue that you can create all level lines in one call and no need to loop.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by