how to make my graph in center without moving it or dragging it to the center
2 ビュー (過去 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,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/869860/image.png)
i want the graph to be like this automatically ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/869865/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/869865/image.png)
0 件のコメント
採用された回答
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)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!