Professional Documents
Culture Documents
Computacin y Programacin
Yussef Farran
yfarran@udec.cl
Ejemplo
6
Graficar un trazo
5.5
entre los puntos
x1=2, y1=3 5
4.5
y 4
3.5
x2=5, y2=6 3
2 2.5 3 3.5 4 4.5 5
Graficos 2D
Los grficos estn basados en la visualizacin
de elementos a partir de un vector
4.5
4
y=[1 2 3 3 5 3 3 2 1]
3.5
3
x=[1 2 3 4 5 6 7 8 9]
2.5
1.5
1
1 2 3 4 5 6 7 8 9
Para dibujar una grafica 2D
Primero: generar los vectores con los puntos
a graficar
- un vector para cada eje
>> s=[1 3 2 4 5 3]
s=
132453
>> plot(s)
>> grid
ejemplo
queremos dibujar la grfica de la funcin
y = sen(x)
>>plot(x,y)
Un ejemplo para graficar
x=-4:.01:4; y=sin(x); plot(x,y), grid, title('Funcin seno(x)')
Otro ejemplo
x= -3 : 0.2 : 3;
y = exp(-x.*x); plot(x,y)
donde
- x e y: son vectores de la misma longitud
- opciones: color, estilo, otros del grfico
The short names and long names are MATLAB strings that specify one of eight predefined
colors. The RGB triple is a three-element row vector whose elements specify the
intensities of the red, green, and blue components of the color; the intensities must be in
the range [0 1]. The following table lists the predefined colors and their RGB equivalents.
y yellow s square
k black d diamond
v triangle (down)
^ triangle (up)
p pentagram
h hexagram
La funcin plot(), en sus diversas
variantes, no hace otra cosa que dibujar
vectores.
Un ejemplo muy sencillo de esta funcin,
en el que se le pasa un nico vector
como argumento, es el siguiente:
>> z=[1 3 2 4 5 3]
z=
132453
>> plot(z)
t='r-^
plot(z, t)
plot (x,y,'r-',x,y,'go')
Plotea 2 veces la
funcin con una lnea
roja slida r-
interpolando crculos
verdes go
Construir un grfico de temperaturas
grid