How to make a 2D plot of a function with an additional parameter, which I can change "live"?

조회 수: 2 (최근 30일)
Hello, guys!
Imagine that we have a simple function y=x+1+C. I'd like to have a 2D plot for x-y and add an additional "bar" to change the parameter "C". Any ideas how I can do it?

답변 (2개)

Jorge Mario Guerra González
Jorge Mario Guerra González 2017년 1월 23일
there is option to link plot when you open figure
for example:
C=0;
x=1:1:100;
y=x+1;
plot(x,y)
then enable plot linking
linkdata on
Check what happends when you change C value and reassign Y:
C=1000;
y=x+1+C;
It can be enabled from that button as well.

Vlad Matjuschkin
Vlad Matjuschkin 2017년 1월 23일
Hi Jorge,
It works, BUT, to change the "C" you need to type
C=1000;
y=x+1+C;
every time.
Let's say, we want to check one hundred values C=1:1:100. We will spend lots of time by typing that again and again ... Is there any other method or app? I simply want "shift" the C-value up and down and see how the function will change.*
*I saw one guy could do it in Excel. He said he installed a special "macro" ... People do it in Maple as well. If excel can do it, why not MATLAB?
  댓글 수: 2
Jorge Mario Guerra González
Jorge Mario Guerra González 2017년 1월 23일
Well, typing C=... is just an example, if you are working on a GUI
then add the command
linkdata on %which enables linkdata on your axes.
put that into the callback of the slider. Then instead of typing C, you put something like...
handles.C=get(handles.slider1,'Value');
y=1+x+C;
axes(hanldes.axes1) %Select the axes you want to plot it on
plot(x,y)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by