Matlab - dibujar un triangulo de n filas empleando el caracter asterisco

 
Vista:

dibujar un triangulo de n filas empleando el caracter asterisco

Publicado por raul (1 intervención) el 26/11/2014 00:24:07
beunas tardes necesito crear un archivo que dibuje un triangulo de n filas empleando el caracter asterisco con la sentencia
for.... end
while end
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de GILMER

dibujar un triangulo de n filas empleando el caracter asterisco

Publicado por GILMER (3 intervenciones) el 01/12/2014 01:33:44
Saludos;

Espero que sea de ayuda, tengo un modelo de dibujo de una cuadrado de n filas empleando el carácter asterisco.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
global xl yl
clear all
clc;
nc=4;
ms=[1  ,   10,   0   ,   0   ,  10  ,  0   , 0 ;
    1  ,   10,   10  ,   0   ,  10  ,  10  , 0 ;
    1  ,   10,   10  ,  10   ,   0  ,  10  , 0 ;
    1  ,   10,    0  ,  10   ,   0  ,   0  , 0];
nb=0;
for i=1:nc
    if ms(i,1) == 1
        x1=ms(i,3);
        y1=ms(i,4);
        x2=ms(i,5);
        y2=ms(i,6);
        ne=ms(i,2);
        [xl1,yl1]=rectline(x1,y1,x2,y2,ne);
        for j=1:ne
            nb=nb+1;
            xl(nb)=xl1(j);
            yl(nb)=yl1(j);
        end
    end
end
plot(xl,yl,'m*')
 
function [xl,yl]=rectline(xj,yj,xk,yk,ne)
%
%Function RECTLINE evaluates:
%    The coordinates of the  end points of the constant
%    elements on straight line segment using its end coordinates
%    xl  : x coordinate of the end points of the boundary elements
%    yl  : y coordinate of the end points of the boundary elements
 
dx=xk-xj;
dy=yk-yj;
xl=zeros(ne,1);
yl=zeros(ne,1);
for j=1:ne
    xl(j)=xj+(j-1)*dx/ne;
    yl(j)=yj+(j-1)*dy/ne;
end

Gilmer
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar