Getting the Incorrect Plot

조회 수: 5 (최근 30일)
Jonathan Fletcher
Jonathan Fletcher 2019년 1월 28일
답변: Ahmed Abuelgasim 2019년 10월 16일
I have a function (func) given to me with desired x-values (x). The assignment is to plot func while also plotting the x-intercepts. It appears to me that I am getting the correct values when I check the x/y data points, but the graph does not line up.
x = -10:.1:8;
func = (x-6).*((x.^2)-1).*(x+8);
plot(func);
title("Graph of Function");
xlabel("Vector Values");
ylabel("Function Values");
hold on;
%Plots the x-intercepts
[~,cols] = size(func);
for i=1:cols
if func(i) == 0
plot(x(i),0,'*r')
end
end
The x-intercepts are correct and the data points are correct; however, my plot does not line up. Not sure what is wrong. Any help would be great!

채택된 답변

Kevin Phung
Kevin Phung 2019년 1월 29일
편집: Kevin Phung 2019년 1월 29일
x = -10:.1:8;
func = (x-6).*((x.^2)-1).*(x+8);
plot(x,func);
title("Graph of Function");
xlabel("Vector Values");
ylabel("Function Values");
hold on;
%Plots the x-intercepts
indx = find(func==0);
plot(x(indx),zeros(1,numel(indx)),'*')
edit: what went wrong is that you didnt plot(x,func) in the beginning, so the scaling of the x axis was different.
  댓글 수: 1
Jonathan Fletcher
Jonathan Fletcher 2019년 1월 29일
Wow. I can't tell you how long I have been looking at that for. Thanks!

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

추가 답변 (1개)

Ahmed Abuelgasim
Ahmed Abuelgasim 2019년 10월 16일
Guys,
In my below code, x-axis doesn't type or show the correct vaules. please your support.
x=[x,LTE_1_RSRP];
y=[y,LTE_2_RSRP];
plot (x, 'r-', 'linewidth', 3);hold on
plot (y, 'g-', 'linewidth', 3);hold on
grid minor
xlabel('RSRP of LTE Cell One')
ylabel('RSRP of LTE Cell Two')
title('RSRP Varition in LTE Cells')
legend('RSRP_1', 'RSRP_2')

카테고리

Help CenterFile Exchange에서 Converters (High Power)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by