필터 지우기
필터 지우기

How to fix anomalies in graphs

조회 수: 2 (최근 30일)
okoth ochola
okoth ochola 2023년 2월 9일
댓글: okoth ochola 2023년 2월 10일
Hello, am trying to plot approximated and actual pdf on on graph, however the kind of figures am recieving are abnormal as illustrated in the figure below. What can be causing this? How can fix it. Previuosly it used not to give such output till I upgraded to later versions of matlab. The approximated plot should be a line graph.

채택된 답변

Steven Lord
Steven Lord 2023년 2월 9일
It looks like you may be calling plot with x data that is not sorted. Compare plotting a sine curve with sorted data:
x = 0:360;
y = sind(x);
plot(x, y)
with the same call but the x data shuffled.
xs = x(randperm(numel(x)));
ys = sind(xs);
figure
plot(xs, ys)
You can see the general shape of the sine curve, but there are points that have very different x values that are connected with one another. Try calling sort on your x data (and using the second output to reorder the y data if it's already been computed) before calling plot.
[xs2, indices] = sort(xs);
ys2 = ys(indices); % Sort ys in the same order as xs was sorted
figure
plot(xs2, ys2)
  댓글 수: 1
okoth ochola
okoth ochola 2023년 2월 10일
Thank you so musch @Steven Lord this has saved me. However sir, why did it work for me without sorting aoruound a month ago? I used the same data set, just out of curiosity?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by