how to make my graph in center without moving it or dragging it to the center

1 次查看(过去 30 天)
fprintf('Please choose any type of signal below.\n1. Impulse\n2. Step function\n3. DC Source\n4. Signum function\n5. Rising exponent function\n6. Cosine function\n7. Sine function\n8. Square function\n9. Triangular function\n10. Symmetrical decaying exponent function')
s=input('\nSignal number: ');
a=input('Please choose any of these signal transformation\n1. Time scale\n2. Time shift\n3. Time inversion\n4. Amplitude scale\n5. Amplitude Shift\n6. Amplitude inversion\n');
switch (s)
case 7
A=input('Enter Amplitude:');
F= input('Enter frequency:');
t=0:0.01:4;
y= A*sin(2*pi*F*t);
plot(t,y,'b')
title ('Sine Wave')
xlabel ('Time')
ylabel('Amplitude')
grid on
hold on
switch (a)
case 1 %time scale
z= input('Enter time scale value:');
y= A*sin(2*pi*F*t);
plot((z\t),y,'k')
grid on
hold off
case 2 %time shifting
z= input('Enter time shifting value:');
y= A*sin(2*pi*F*t);
plot((t-z),y,'k')
grid on
hold off
case 3 %time inversion
y= A*sin(2*pi*F*(-t));
plot(t,y,'g')
grid on
hold off
case 4 %amplitude scale
z=input('Enter amplitude scale value:');
y= z*(A*sin(2*pi*F*t));
plot(t,y,'k');
grid on
hold off
case 5 %amplitude shift
z=input('Enter amplitude shift value:');
y= (A*sin(2*pi*F*t))-z;
plot(t,y,'k');
grid on
hold off
case 6 %amplitude inversion
y= -A*sin(2*pi*F*t);
plot(t,y,'k')
grid on
hold off
end
instead of this graph,
i want the graph to be like this automatically

采纳的回答

DGM
DGM 2022-1-22
编辑:DGM 2022-1-22
There's no need for all this code repetition. The cases should not be nested. Create the unmodified vectors, create the modified copies, then plot.
fprintf('Please choose any type of signal below.\n1. Impulse\n2. Step function\n3. DC Source\n4. Signum function\n5. Rising exponent function\n6. Cosine function\n7. Sine function\n8. Square function\n9. Triangular function\n10. Symmetrical decaying exponent function')
s = input('\nSignal number: ');
a = input('Please choose any of these signal transformation\n1. Time scale\n2. Time shift\n3. Time inversion\n4. Amplitude scale\n5. Amplitude Shift\n6. Amplitude inversion\n');
switch (s)
% ... other cases
case 7
A = input('Enter Amplitude: '); % trailing space for clarity
F = input('Enter frequency: ');
t = 0:0.01:4;
y = A*sin(2*pi*F*t);
figtitle = 'Sine Wave'; % for later
% ... other cases
end
switch (a)
% ... other cases
case 2 %time shifting
z = input('Enter time shifting value: ');
tmod = t-z;
ymod = y;
% ... other cases
case 4 %amplitude scale
z = input('Enter amplitude scale value: ');
tmod = t;
ymod = z*y;
% ... other cases
end
% do the plotting last
plot(t,y,'b')
hold on
plot(tmod,ymod,'k')
hold off
title(figtitle)
xlabel('Time')
ylabel('Amplitude')
grid on
% adjust limits to create padding
xlim(xlim + [-1 1]*range(xlim)*0.2)
ylim(ylim + [-1 1]*range(ylim)*0.2)
  3 个评论
Mya
Mya 2022-1-22
ouh ok i know hich part i did wrong hihi....i accidentally put the plot coding before end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Network Parameters 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by