필터 지우기
필터 지우기

the code below I'm trying to plot a loglog graph, but everytime I run the code I keep getting an empty graph, then when i use the brush i can see the points. can anyone help

조회 수: 1 (최근 30일)
n=10;
x=0.2;
for i=1:n
h=1/i;
cf=dot([1 -2 1],[(cos(pi*(x+h))) cos(pi*x) cos(pi*(x-h))])/h^2;
rf=dot([2 -5 4 -1],[cos(pi*x) ;cos((pi*(x+h))) ;cos((pi*(x+2*h))); cos(pi*(x+3*h))])/h^2;
ec=abs((-pi^2*cos(pi*x))-cf);
er=abs((-pi^2*cos(pi*x))-rf);
loglog(h,ec,'g');
hold on
loglog(h,er,'r');
hold on
end
xlabel('h')
ylabel('ec + er')

채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 8일
You are only plotting one point at a time so you will not get connecting lines. But you have not specified any marker shape or marker size so you cannot see the markers.
Are you trying for lines or for a scatter plot?
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 2월 8일
At the time you do
loglog(h,ec,'g');
your h is a scalar (1/i) and your ec is a scalar calculated just above. You are therefore using loglog() of one scalar against another. That plots one point. However, when you use plot() without specifying a data marker, the points are not plotted... so you get no visible output. If you had used
loglog(h,ec,'*g');
you would have gotten visible individual points.
But you want lines. To get lines you should store the computations and then plot() the results.
n=10;
x=0.2;
for i=1:n
h(i) = 1/i;
cf = dot([1 -2 1],[(cos(pi*(x+h(i)))) cos(pi*x) cos(pi*(x-h(i)))])/h(i)^2;
rf = dot([2 -5 4 -1],[cos(pi*x) ;cos((pi*(x+h(i)))) ;cos((pi*(x+2*h(i)))); cos(pi*(x+3*h(i)))])/h(i)^2;
ec(i) = abs((-pi^2*cos(pi*x))-cf);
er(i) = abs((-pi^2*cos(pi*x))-rf);
end
loglog(h, ec, 'g');
hold on
loglog(h, er, 'r');
hold off
xlabel('h')
ylabel('ec + er')
Walter Roberson
Walter Roberson 2016년 2월 9일
Is there a reason you did not copy the code I gave that shows how to save the points?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by