How to Stretching and shrinking a graph

조회 수: 29 (최근 30일)
Antonella
Antonella 2013년 10월 30일
댓글: Antonella 2013년 10월 30일
I have the function y = sin(x) and i have to stretching the graph of it. I have also to shrinking it. How can i write this in matlab?
x = 1:.01:10; y = sin(x); for i = 1 : length(y)
how i have to continue...???
Thanks in advance!!!
  댓글 수: 1
sixwwwwww
sixwwwwww 2013년 10월 30일
What do you mean by stretching or shrinking? and also by the "sin" is a built-in function in MATLAB so don't use as name of your function. Do you want to input some scaling factor as input in you code and want out be scaled accordingly?

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

답변 (2개)

sixwwwwww
sixwwwwww 2013년 10월 30일
편집: sixwwwwww 2013년 10월 30일
Beside the comment you can do something like this:
scaling_factor = 2; % define the scaling factor and graph will scale accordingly
x = 1:.01:10 * scaling_factor;
y = sin(x);
figure, plot(x, y), title(strcat('Scaling factor = ', num2str(scaling_factor)))
I hope it helps. Good luck!
  댓글 수: 1
Antonella
Antonella 2013년 10월 30일
Thanks really much for this help! ;)

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


Wayne King
Wayne King 2013년 10월 30일
You can simply dilate the independent variable in the function
x = 0:0.01:10;
y = sin(x);
y2 = sin(x/2);
plot(x,y); hold on;
plot(x,y2,'r')
To shrink the function:
y3 = sin(2*x);
plot(x,y3,'k')
  댓글 수: 1
Antonella
Antonella 2013년 10월 30일
Thanks very much for your availability and your help! ;)

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

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by