how to plot discontinuous functions in matlab?

조회 수: 116 (최근 30일)
rr mm
rr mm 2015년 9월 6일
답변: Daniel Garside 2018년 3월 2일
Hi everyone!
I want to plot a simple floor function without connections between points in separate steps. I do this in maple with discont=true property. I used scatter function but I want to have straight line instead of circles. how can I do the same in matlab?
thanks for your attention!

답변 (3개)

Daniel Garside
Daniel Garside 2018년 3월 2일
If you just want the visuals something like this works:
for i=1:10
plot([i, i+1],[i,i])
end

the cyclist
the cyclist 2015년 9월 6일
Here is an example that sounds like what you want:
figure
x = 1:10;
y = 3 + (x>5);
h = plot(x,y,'.');
set(h,'MarkerSize',24)
ylim([2 5])
  댓글 수: 1
rr mm
rr mm 2015년 9월 6일
편집: rr mm 2015년 9월 6일
Dear friend,
it does the same scatter function, the result must be like this image.
thanks

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


Walter Roberson
Walter Roberson 2015년 9월 6일
Every function sampled at a finite number of points is effectively discontinuous and there is no way to automatically tell from the finite list of sampled points whether two adjacent points "should" be joined or not.
You need to either add some intelligence about where the discontinuities are, or you need to process them symbolically by calling into MuPad's discont() function
syms x
feval(symengine, 'discont', floor(x), sym('x = 1..5'))
and then somehow process the discontinuity set in constructing your numeric plot.
If you were to work in a MuPAD notebook, you could use http://www.mathworks.com/help/symbolic/mupad_ref/plot-function2d.html as that has discontinuity processing turned on by default. I have never seen an answer for what happens if you try to feval() a MuPAD plot from the MATLAB level.

카테고리

Help CenterFile Exchange에서 2-D Function Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by