Effacer les filtres
Effacer les filtres

How to make plot visible?

1 vue (au cours des 30 derniers jours)
Alejandro Urbina
Alejandro Urbina le 29 Fév 2016
I have the following code
t1 = linspace(-15,15,10);
t2 = linspace(-15,15,1);
t3 = linspace(-15,15,.1);
x1 = 3*sin(2*pi*t1/10);
x2 = 3*sin(2*pi*t2/10);
x3 = 3*sin(2*pi*t3/10);
y1 = sin(2*pi*t1/20);
y2 = sin(2*pi*t2/20);
y3 = sin(2*pi*t3/20);
figure
subplot(3,2,1)
plot(t1,x1)
title('x(t)>>dt=10')
subplot(3,2,2)
plot(t2,x2)
title('x(t)>>dt=1')
subplot(3,2,3)
plot(t3,x3)
title('x(t)>>dt=.1')
subplot(3,2,4)
plot(t1,y1)
title('y(t)>>dt=10')
subplot(3,2,5)
plot(t2,y2)
title('y(t)>>dt=1')
subplot(3,2,6)
plot(t3,y3)
title('y(t)>>dt=.1')
clear
when plotted most of the graph dosent show up and i dont know why... can someone please give some input please, ill really appreciate any kind of help thank you

Réponses (2)

Stephen23
Stephen23 le 29 Fév 2016
Modifié(e) : Stephen23 le 29 Fév 2016
Problem You did not read the linspace documentation before using it. The linspace documentation says clearly: " y = linspace(x1,x2,n) generates n points."
Lets now see how you have used it:
t1 = linspace(-15,15,10);
t2 = linspace(-15,15,1);
t3 = linspace(-15,15,.1);
You have specified that the first generates ten points, the second one point, and the third zero points. And you then plot 10/1/0 points of data. You can try it yourself:
>> linspace(-15,15,10) % ten points
ans =
-15.0000 -11.6667 -8.3333 -5.0000 -1.6667 1.6667 5.0000 8.3333 11.6667 15.0000
>> linspace(-15,15,1) % one point
ans =
15
>> linspace(-15,15,0.1) % zero points
ans =
Empty matrix: 1-by-0
And when you plot one point, or zero points: what do you expect to show up?
Solution
Read the documentation. Learn to try things and experiment. If you had actually looked at the sizes of t1, etc, then you could have figured out where the problem was.
For this code, use the colon operator:
>> -15:10:15
ans =
-15 -5 5 15
>> -15:1:15
ans =
Columns 1 through 23
-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
Columns 24 through 31
8 9 10 11 12 13 14 15
>> -15:0.1:15
ans =
Columns 1 through 13
-15.0000 -14.9000 -14.8000 -14.7000 -14.6000 -14.5000 -14.4000 -14.3000 -14.2000 -14.1000 -14.0000 -13.9000 -13.8000
... lots here
Columns 287 through 299
13.6000 13.7000 13.8000 13.9000 14.0000 14.1000 14.2000 14.3000 14.4000 14.5000 14.6000 14.7000 14.8000
Columns 300 through 301
14.9000 15.0000
You also need to learn to get the computer to do your work for you: copy-and-pasting code is slow, inflexible, and buggy. Computers are good at repeating things lots of times, so just use a loop!:
V = [10,1,0.1]; % vector of step sizes
N = numel(V);
%
figure()
for k = 1:N
T = -15:V(k):+15;
X = 3*sin(2*pi*T/10);
Y = sin(2*pi*T/20);
% plot X
subplot(3,2,2*(k-1)+1)
plot(T,X)
title(sprintf('x(t)>>dt=%g',V(k)))
% plot Y
subplot(3,2,2*(k-1)+2)
plot(T,X)
title(sprintf('y(t)>>dt=%g',V(k)))
end
which creates this plot:

Star Strider
Star Strider le 29 Fév 2016
If you actually put the clear call in your code, that could explain the reason nothing shows up.
From the documentation:
  • clear removes all variables from the current workspace, releasing them from system memory.

Catégories

En savoir plus sur Line Plots 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