Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Mya
Mya le 22 Jan 2022
Commenté : Mya le 22 Jan 2022
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

Réponse acceptée

DGM
DGM le 22 Jan 2022
Modifié(e) : DGM le 22 Jan 2022
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 commentaires
Mya
Mya le 22 Jan 2022
ouh ok i know hich part i did wrong hihi....i accidentally put the plot coding before end
Mya
Mya le 22 Jan 2022
tq so much for sharing this

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Network Parameters dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by