tag:blogger.com,1999:blog-64916782715819087532024-02-07T02:26:00.712-06:00MATLAB TYPJorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.comBlogger72125tag:blogger.com,1999:blog-6491678271581908753.post-39980669691226950332016-08-09T15:42:00.000-05:002016-08-09T15:42:14.955-05:00Rotar matrices en MATLABLa rotación de matrices consiste en redefinir la posición de sus elementos mediante una modificación que no afecta el valor de sus elementos. Para comenzar, suponga que se tiene un vector v definido como sigue:<br />
<br />
<span class="math display"><em>v</em> = [<em>v</em><sub>1</sub>, <em>v</em><sub>2</sub>, <em>v</em><sub>3</sub>, ⋯, <em>v</em><sub><em>n</em> − 1</sub>, <em>v</em><sub><em>n</em></sub>]</span><br />
<br />
Y sea vea v' el vector cuyas componentes son las mismas que v pero dispuestas en un orden inverso, es decir:<br />
<br /><span class="math display"><em>v</em>′=[<em>v</em><sub><em>n</em></sub>, <em>v</em><sub><em>n</em> − 1</sub>, ⋯, <em>v</em><sub>3</sub>, <em>v</em><sub>2</sub>, <em>v</em><sub>1</sub>]</span><br />
<br />
En MATLAB invertir el orden de los elementos de un vector resulta una tarea muy sencilla, esto puede lograrse indexando los elementos de la forma que a continuación se muestra:<br />
<br />
<pre><code>>> v=[-2 5 8 7 3 0] % Vector original
v =
-2 5 8 7 3 0
>> vp=v(end:-1:1) % Vector con elementos invertidos
vp =
0 3 7 8 5 -2</code></pre>
<br />
La anterior es una forma muy simple de realizar dicha tarea, pero si usted prefiere el uso de funciones existe para tal fin la función fliplr cuya tarea es exactamente esa, extendiéndose su uso también a matrices, véase el ejemplo utilizando el mismo vector definido anteriormente:<br />
<br />
<pre><code>>> vp=fliplr(v)
vp =
0 3 7 8 5 -2</code></pre>
<br />
La función fliplr rota una matriz en un eje vertical, de tal modo que las columnas situadas a la izquierda queden en la parte derecha. Véase el ejemplo a continuación:<br />
<br />
<pre><code>>> A=randi(10,3)
A =
4 5 3
2 2 4
5 6 6
>> Ar=fliplr(A)
Ar =
3 5 4
4 2 2
6 6 5</code></pre>
<br />
Está claro que fliplr ejecuta una rotación basada en las columnas, pero MATLAB dispone también de la función flipud que ejerce una rotación en un eje horizontal o basada en las filas, enseguida se muestra un ejemplo:<br />
<br />
<pre><code>>> A=randi(10,4)
A =
5 6 8 2
9 4 5 3
8 2 1 5
10 7 3 6
>> Ar=flipud(A)
Ar =
10 7 3 6
8 2 1 5
9 4 5 3
5 6 8 2</code></pre>
<br />
Además de las anteriores MATLAB proporciona la función rot90 que permite girar la matriz en un ángulo múltiplo de 90° en el sentido contrario a las manecillas del reloj, de manera informal es como si la matriz rodase en dirección izquierda. Los argumentos de entrada de la función son primeramente la matriz a rotar y como segundo argumento un escalar entero que indica el múltiplo de 90° con el cual habrá de ejecutarse la rotación, si no se introduce un segundo argumento se asume que este será unitario. Véanse los ejemplos a continuación:<br />
<br />
<pre><code>>> A=randi(20,3)
A =
14 8 10
1 19 9
13 1 10
>> A90=rot90(A) % Matriz rotada 90°
A90 =
10 9 10
8 19 1
14 1 13
>> A180=rot90(A,2) % Matriz rotada en 180°
A180 =
10 1 13
9 19 1
10 8 14
>> A270=rot90(A,3) % Matriz rotada 270°
A270 =
13 1 14
1 19 8
10 9 10</code></pre>
Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-23372657134134017372016-08-09T15:34:00.001-05:002016-08-09T15:35:44.449-05:00Resolver ecuaciones e inecuaciones algebraicasUna ecuación es una igualdad matemática entre dos expresiones algebraicas en las que aparecen valores conocidos y una variable desconocida (incógnita), relacionados mediante operaciones matemáticas básicas, ejemplos de ecuaciones se muestran a continuación:<br />
<br />
<span class="math display">$$ 3x^2 + 2x - 2 = 0 $$</span><br />
<br />
<span class="math display">$$ x+\frac{3}{7}=2 $$</span><br />
<br />
<span class="math display">$$ \cos(x)+sin(\frac{\pi}{2})=0 $$</span><br />
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Las ecuaciones algebraicas sirven para modelar situaciones poco complejas pero que requieren el uso de la herramienta matemática para obtener una solución satisfactoria. Existen diversos métodos para resolver ecuaciones, los cuales se aplican dependiendo del tipo de ecuación, incluso hay fórmulas establecidas para algunos tipos de ecuaciones que minimizan el esfuerzo de cálculo.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
MATLAB dispone de la función solve perteneciente al Symbolic Math Toolbox, la cual permite resolver ecuaciones, inecuaciones y sistemas de ecuaciones; la sintaxis general de la función <code style="white-space: pre;">solve</code> es:</div>
<div style="text-align: justify;">
<br /></div>
<pre style="text-align: justify;"><code>solve(ec, var);</code></pre>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Donde ec es una ecuación algebraica definida usando variables simbólicas y var es la incógnita respecto a la cual se resuelve la ecuación dada.</div>
<div style="text-align: justify;">
<br /></div>
A manera de ejemplo se resolverá la siguiente ecuación lineal<br />
<br />
<span class="math display">$$ x+3=2 $$</span><br />
<span class="math display"><br /></span>
<br />
<pre><code>>> x=sym('x');
>> solve(x+3==2,x)
ans =
-1</code></pre>
<br />
<div style="text-align: justify;">
Es importante hacer mención que para especificar una igualdad se utilizan dos signos, dado que un sólo signo hace referencia a una asignación.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Si no se especifica el segundo miembro de la igualdad, MATLAB asumirá que la expresión estará igualada a cero, es decir, para resolver la ecuación:</div>
<br />
$$ x^2 - 2x - 1 = 0 $$<br />
<br />
Puede hacerlo de las diversas formas que enseguida se muestran:<br />
<br />
<pre><code>>> solve(x^2-2*x-1==0,x)
ans =
2^(1/2) + 1
1 - 2^(1/2)
>> solve(x^2-2*x-1,x)
ans =
2^(1/2) + 1
1 - 2^(1/2)
>> solve(x^2-2*x-1)
ans =
2^(1/2) + 1
1 - 2^(1/2)</code></pre>
<br />
Para resolver desigualdades o inecuaciones la sintaxis es prácticamente la misma, claro, sólo hay que utilizar los operadores relacionales mayor que o menor que en lugar del signo de igualdad. Por ejemplo, resolviendo la siguiente desigualdad<br />
<br />
<span class="math display">$$ x+2>10 $$</span><br />
<br />
<pre><code>>> solve(x+2>10,x)
ans =
Dom::Interval(8, Inf)</code></pre>
<br />
<div style="text-align: justify;">
MATLAB devuelve el intervalo solución para la inecuación, en este caso <span class="math display">$ (8,\infty) $</span>. Para el caso de un intervalo cerrado MATLAB devuelve entre corchetes el valor del límite correspondiente, por ejemplo:</div>
<br />
<pre><code>>> solve(x+2>=10,x)
ans =
Dom::Interval([8], Inf)</code></pre>
<br />
<div style="text-align: justify;">
Un sistema de ecuaciones se compone de dos o más ecuaciones y un número equivalente de valores desconocidos, es posible resolver sistemas de ecuaciones utilizando también la función solve con la sintaxis siguiente:</div>
<div style="text-align: justify;">
<br /></div>
<pre><code>solve(ec1,ec2,ec3,…)</code></pre>
<br />
Un ejemplo, resolver el siguiente sistema de ecuaciones:<br />
<br />
<span class="math display"><em>x</em> + <em>y</em> = 4</span><br />
<br />
<span class="math display"><em>x</em> − <em>y</em> = 3</span><br />
<pre><code>
</code></pre>
<pre><code>>> syms x y
>> sol=solve(x+y==4,x-y==3)
sol =
x: [1x1 sym]
y: [1x1 sym]</code></pre>
<br />
<div style="text-align: justify;">
Para visualizar los resultados puede acceder a los campos de cada variable como se muestra enseguida:</div>
<br />
<pre><code>>> sol.x
ans =
7/2
>> sol.y
ans =
1/2</code></pre>
Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com2tag:blogger.com,1999:blog-6491678271581908753.post-25289450788049014252016-08-04T00:25:00.001-05:002016-08-04T00:26:59.571-05:00Convertir una imagen a escala de grises<h3 id="la-manera-rápida">
La manera rápida</h3>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Si cuenta con el <em>Image Processing Toolbox</em> MATLAB dispone de una función llamada <code style="white-space: pre;">rgb2gray</code> que permite convertir una imagen RGB a una en escala de grises, ej:</div>
<br />
<div class="sourceCode" style="overflow-x: auto;">
<pre class="sourceCode matlab"><code class="sourceCode matlab">X = imread(<span class="st" style="color: #4070a0;">'lenna.png'</span>);
XG = rgb2gray(X);
imshow(XG);</code></pre>
</div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyodjfWbKr45SN5e8yUhOZQ6wTMTQqvUPX8IJOS6w9IUJjJUiJuGy7bYpGQFeLMbgeymwDQxo69lpiwJjBA9zDnVKZkwtjFaToUtV7xDdfnDphVSetCywn6YML98itQWTKpm-cALh0tSzs/s1600/lenna.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyodjfWbKr45SN5e8yUhOZQ6wTMTQqvUPX8IJOS6w9IUJjJUiJuGy7bYpGQFeLMbgeymwDQxo69lpiwJjBA9zDnVKZkwtjFaToUtV7xDdfnDphVSetCywn6YML98itQWTKpm-cALh0tSzs/s200/lenna.png" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Imagen original</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjkcg8hVS3viKv1RjQxTq-KRvNtgyFrRFOJmGj23d3qQGhFvtHf02wi-16oQl_9gdaGW1LY-wjPHjlMqvk0oNcenRGJXwnQHVr_hpvAoaTAsPMnoix1Y9g9M3LFmxu3lmKeJTrDHDCbFNf/s1600/lenna_gris.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjkcg8hVS3viKv1RjQxTq-KRvNtgyFrRFOJmGj23d3qQGhFvtHf02wi-16oQl_9gdaGW1LY-wjPHjlMqvk0oNcenRGJXwnQHVr_hpvAoaTAsPMnoix1Y9g9M3LFmxu3lmKeJTrDHDCbFNf/s200/lenna_gris.png" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Imagen en escala de grises</td></tr>
</tbody></table>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Como puede notar es muy simple, sólo necesita pasar como argumento la matriz que contiene la información de la imagen RGB.</div>
<div style="text-align: justify;">
<br /></div>
<h3 id="la-otra-un-poco-de-algoritmos...">
La otra, un poco de algoritmos...</h3>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Si no dispone del toolbox de procesamiento de imagen, entonces puede implementar su propio algoritmo para realizar dicha tarea.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
El algoritmo más simple es el del <em>promedio</em> (average method), que consiste en calcular el promedio de los canales RGB y asignarlos al pixel correspondiente en la imagen de grises. Por ejemplo dada una matriz de <strong>MxNx3</strong> correspondiente a una imagen, el pixel de la matriz de grises en la posición <span class="math inline">(<em>i</em>, <em>j</em>)</span> se calcula como sigue:</div>
<br />
<span class="math display">$$ XG_{i,j} = \frac{X_{i,j,1} + X_{i,j,2} + X_{i,j,3}}{3} $$</span><br />
<br />
<div style="text-align: justify;">
Donde <code style="white-space: pre;">XG</code> es la matriz de grises, de dimensiones <strong>MxN</strong>. Y <span class="math inline"><em>X</em><sub><em>i</em>, <em>j</em>, 1</sub></span>, <span class="math inline"><em>X</em><sub><em>i</em>, <em>j</em>, 2</sub></span> y <span class="math inline"><em>X</em><sub><em>i</em>, <em>j</em>, 3</sub></span> las componentes correspondientes a los canales R, G y B, respectivamente.</div>
<br />
Implementando esto en MATLAB:<br />
<br />
<div class="sourceCode" style="overflow-x: auto;">
<pre class="sourceCode matlab"><code class="sourceCode matlab">X = imread(<span class="st" style="color: #4070a0;">'lenna.png'</span>);
XG = uint8(mean(X,<span class="fl" style="color: #40a070;">3</span>));
imshow(XG);</code></pre>
</div>
<br />
<div style="text-align: justify;">
¿Bastante simple verdad?, lo que hacemos es hacer el promedio en la dimensión 3, es decir, para cada pixel. La conversión a entero de 8-bits (<code style="white-space: pre;">uint8</code>) es necesaria para que se muestre correctamente cuando utilizamos <code style="white-space: pre;">imshow</code>, dado que la función <code style="white-space: pre;">mean</code> devuelve una matriz de tipo <code style="white-space: pre;">double</code>.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Otro método para convertir a escala de grises es el de la luminosidad (luminosity method) que consiste en asignar una proporción específica (ponderada) a cada uno de los canales, dependiendo la aportación de estos. De hecho MATLAB utiliza este tipo de transformación en la función <code style="white-space: pre;">rgb2gray</code>. Con este método, la expresión para calcular el valor de un pixel de grises viene dado por:</div>
<br />
<span class="math display"><em>X</em><em>G</em><sub><em>i</em>, <em>j</em></sub> = 0.2889 <em>X</em><sub><em>i</em>, <em>j</em>, 1</sub> + 0.5870 <em>X</em><sub><em>i</em>, <em>j</em>, 2</sub> + 0.1140 <em>X</em><sub><em>i</em>, <em>j</em>, 3</sub></span><br />
<br />
LLevando esto a un código MATLAB:<br />
<br />
<div class="sourceCode" style="overflow-x: auto;">
<pre class="sourceCode matlab"><code class="sourceCode matlab">X = imread(<span class="st" style="color: #4070a0;">'img/lenna.png'</span>);
k = [<span class="fl" style="color: #40a070;">0.2989</span> <span class="fl" style="color: #40a070;">0.5870</span> <span class="fl" style="color: #40a070;">0.1140</span>];
XG = X(:,:,<span class="fl" style="color: #40a070;">1</span>)*k(<span class="fl" style="color: #40a070;">1</span>) + X(:,:,<span class="fl" style="color: #40a070;">2</span>)*k(<span class="fl" style="color: #40a070;">2</span>) + X(:,:,<span class="fl" style="color: #40a070;">3</span>)*k(<span class="fl" style="color: #40a070;">3</span>);
imshow(XG)</code></pre>
</div>
Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com4tag:blogger.com,1999:blog-6491678271581908753.post-44396885142942169992016-05-10T00:17:00.000-05:002016-05-10T00:34:10.263-05:00Detección de bordes en imágenes con MATLABLa detección de bordes en MATLAB es una de las operaciones de procesamiento de imágenes más común y básica, cuyo objetivo es determinar las regiones en una imagen que presentan cambios significativos de intensidad en los pixeles que la conforman.<br />
<br />
Recuerde que una imagen en escala de grises puede expresarse como una función bivariable <span class="math inline"><em>f</em>(<em>x</em>, <em>y</em>)</span>, donde x e y son las coordenadas de ubicación (fila, columna). Así una forma sencilla de detectar los bordes en una imagen es utilizar el gradiente, mismo que determina la tasa de variación en ambas direcciones de una función bivariable, dado por:<br />
<br />
<span class="math display">$$ \nabla f = \begin{bmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \end{bmatrix} $$</span><br />
<br />
Aunque claro, para nuestros propósitos lo que usaremos es la magnitud del gradiente:<br />
<br />
<span class="math display">$$ |\nabla f| = \sqrt{ \left(\frac{\partial f}{\partial x}\right)^2 + \left(\frac{\partial f}{\partial y}\right)^2} $$</span><br />
<br />
Así, para determinar los bordes en una imagen, o lo que sería lo mismo: localizar las regiones en donde la magnitud del gradiente es mayor, podemos utilizar la función <code style="white-space: pre;">gradient</code>, vea el siguiente ejemplo:<br />
<br />
<div class="sourceCode" style="overflow-x: auto;">
<pre class="sourceCode matlab"><code class="sourceCode matlab">X = imread(<span class="st" style="color: #4070a0;">'Lenna.png'</span>);
XG = rgb2gray(X);
[dx,dy] = gradient(double(XG));
M = uint8(sqrt(dx.^<span class="fl" style="color: #40a070;">2</span>+dy.^<span class="fl" style="color: #40a070;">2</span>));
imshow(M);</code></pre>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoSDabyqv-f9Dk0iiSgtSBK2tcZs0ixQm7a9dcpx9aCYSX9zufFRBJngi4MY9B0YMCW-0XA5gdUtksxhc0j5vFeo51BGECwTPOQNaCfNhFYTQ0rsEwWmfADXWPtoi31z0S-I2wT61SdG3h/s1600/lena_grad.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoSDabyqv-f9Dk0iiSgtSBK2tcZs0ixQm7a9dcpx9aCYSX9zufFRBJngi4MY9B0YMCW-0XA5gdUtksxhc0j5vFeo51BGECwTPOQNaCfNhFYTQ0rsEwWmfADXWPtoi31z0S-I2wT61SdG3h/s320/lena_grad.png" width="320" /></a></div>
<br />
<br />
MATLAB cuenta con una función especial para detectar bordes en una imagen: <code style="white-space: pre;">edge</code>, la cual utiliza operadores matriciales especiales que transforman una imagen en escala de grises en una imagen binarizada con bordes resaltados.<br />
<br />
<div class="sourceCode" style="overflow-x: auto;">
<pre class="sourceCode matlab"><code class="sourceCode matlab">X = imread(<span class="st" style="color: #4070a0;">'Lenna.png'</span>);
XG = rgb2gray(X);
XB = edge(XG,<span class="st" style="color: #4070a0;">'sobel'</span>);
imshow(XB);</code></pre>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6PhohHhyphenhyphennk7_E8-yAkrnjhFU27uYh5rdGAgZEQvSUx35igme9OfZs-dtuMCCFtHB03O5Gg3XsYJU5k4JBycXZ0-tLCBkntx2uwlVrFH1LKaC_Vpx2GllVk_aj2tkNfGOSQF-C0r5JteaZ/s1600/lena_sobel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6PhohHhyphenhyphennk7_E8-yAkrnjhFU27uYh5rdGAgZEQvSUx35igme9OfZs-dtuMCCFtHB03O5Gg3XsYJU5k4JBycXZ0-tLCBkntx2uwlVrFH1LKaC_Vpx2GllVk_aj2tkNfGOSQF-C0r5JteaZ/s320/lena_sobel.png" width="320" /></a></div>
<br />Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-51376511451496420782016-01-04T21:11:00.000-06:002016-03-21T22:38:50.648-06:00Ordenar matrices en MATLAB<div style="text-align: justify;">El ordenamiento de datos es una tarea muy común dentro del mundo de la informática y en la programación científica. Se ordenan datos para realizar análisis cualitativos, para la visualización gráfica o cualquier otro procedimiento que requiera datos organizados. Los datos se pueden organizar por criterios diversos, pero en esta sección veremos simplemente como ordenarlos de acuerdo a su valor numérico, en orden ascendente o descendente.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Generalmente los algoritmos de ordenamiento forman parte de los cursos básicos de programación y algorítmica, dada su importancia mencionada con anterioridad. Se estudian por lo general métodos tradicionales como: el método de ordenamiento por selección, ordenamiento por inserción y ordenamiento por combinación.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Ahora, enseguida sólo veremos cómo implementar el método de ordenamiento por selección, puesto que resulta muy didáctico y fácil de programar, y como no estamos en disposición de reinventar la rueda, entonces, para el ordenamiento de las matrices y/o vectores utilizaremos la función sort incluida en el núcleo de MATLAB, y el resto de métodos de ordenamiento tradicionales se propondrán como ejercicios al final de este capítulo.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Así pues, puede revisar el siguiente código:</div><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>X=input('Inserte un vector: ');</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for i=1:length(X)</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> [menor,k]=min(X(i:end));</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> X((i-1)+k)=X(i);</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> X(i)=menor;</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>end</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>disp(X); % Vector ordenado</span><br /><br /><div style="text-align: justify;">El programa anterior tiene como punto de entrada un vector introducido por el usuario de forma interactiva y que puede contener valores numéricos cualesquiera. Una vez se ha introducido el vector, se utiliza un bucle for cuyo recorrido está determinado por la longitud del vector, y en cada iteración se busca el elemento de menor valor ubicado en el sub-arreglo $X(i,i+1,...,n-1,n)$ donde i es el i-ésimo elemento dado por el número de iteración actual, y n el último elemento del arreglo, la función min de MATLAB devuelve dos resultados: el valor y la posición del mínimo encontrado, con ello se procede a intercambiar el valor mínimo encontrado con aquel ubicado en la i-ésima posición del arreglo. Y así, cuando se hayan ejecutado tantas iteraciones como elementos tenga el vector, se habrán ordenado en forma ascendente dichos valores. Si por el contrario necesita ordenar un vector en forma descendente, simplemente habrá de sustituir la función min por max, es decir, buscar un valor máximo en lugar del mínimo en cada iteración, o bien, reutilizar el mismo algoritmo y audazmente rotar el vector resultante mediante la función <span style="font-family: Courier New, Courier, monospace;">fliplr</span>.</div><br />Como se mencionó, en MATLAB todo lo anterior puede reemplazarse utilizando la función <span style="font-family: Courier New, Courier, monospace;">sort</span>.<br />cuya sintaxis más general es:<br /><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>>> sort(X, dim, mod);</span><br /><br /><div style="text-align: justify;">Donde <b>X</b> es la matriz o vector a ordenar, dim es un escalar que puede ser 1 (columnas) o 2 (filas) y que representa la dimensión de referencia sobre la cual se ordenará, y mod es el modo de ordenamiento, que puede ser <span style="font-family: Courier New, Courier, monospace;">'ascend'</span> (menor a mayor) o <span style="font-family: Courier New, Courier, monospace;">'descend'</span> (mayor a menor), por defecto las matrices o vectores se ordenan en forma ascendente. </div><br />Véanse los ejemplos siguientes:<br /><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>>> X=[10 2 8 17 20 1 4 8 9];</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>>> sort(X)</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ans =</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 1 2 4 8 8 9 10 17 20</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>>> M=randi(10,5)</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>M =</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 3 10 3 2 8</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 8 7 2 10 6</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 9 4 9 5 5</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 1 10 8 3 10</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 4 8 4 5 6</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>>> sort(M,1) % Ordenada por columnas</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ans =</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 1 4 2 2 5</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 3 7 3 3 6</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 4 8 4 5 6</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 8 10 8 5 8</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 9 10 9 10 10</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>>> sort(M,2) % Ordenada por filas</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ans =</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 2 3 3 8 10</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 2 6 7 8 10</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 4 5 5 9 9</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 1 3 8 10 10</span><br /><span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span> 4 4 5 6 8</span>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com1tag:blogger.com,1999:blog-6491678271581908753.post-69525295061528369882015-12-19T01:04:00.000-06:002016-03-21T22:38:50.684-06:00Exportar datos de una uitable MATLAB a una tabla en archivo HTML: table2html.<div style="text-align: justify;">La función table2html que se anexa a continuación permite exportar los datos contenidos en una uitable MATLAB a una tabla contenida en un archivo HTML. La utilidad puede ser en aquellos casos donde se requiera elaborar reportes con datos de salida contenidos en una uitable, evidentemente la opción "Publish" de MATLAB permite elaborar un reporte de cualquier script, pero incluye solamente capturas de los objetos gráficos. Esta función se puede adaptar para que en lugar de devolver un archivo HTML completo, solamente devuelva el código HTML de la tabla e incrustar esto posteriormente en un reporte HTML creado de manera independiente.</div><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 1.0pt 1.0pt 1.0pt;"> <div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">function table2html(hTab,filename,opts)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% TABLE2HTML(hTab,filename)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% hTab - Handle de la uitable a "exportar"<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% filename - Nombre del archivo de salida (*.html)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% opts - Estructura de opciones adicionales (Veáse Opciones)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% Exporta una uitable como tabla en un archivo en formato HTML<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% EJEMPLO:<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% f = figure();<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% hTab = uitable(f,'Data',rand(10));<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% table2html(hTab,'miejemplo.html');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% OPCIONES (OPTS)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% <o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% PageTitle - Título de la página web<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% TableTitle - Título de la tabla<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% BgColor - Color de fondo de la tabla<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% FontName - Tipo de fuente utilizada<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% BorderWidth - Ancho del borde de la tabla<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% <o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% EJEMPLO CON OPCIONES:<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% f = figure();<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% opts.PageTitle = 'Ejemplo';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% opts.TableTitle = 'Mi tabla';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% opts.BgColor = '#00FF00';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% opts.FontName = 'Arial';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% opts.BorderWidth = '3';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% hTab = uitable(f,'Data',rand(10));<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% table2html(hTab,'miejemplo.html',opts);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% <o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">%<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% -------------------------------<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% Ver. 0.0.1 || 25/10/2014<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% Jorge De Los Santos<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% delossantosmfq@gmail.com<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% http://labdls.blogspot.mx<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% MIT License<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% -------------------------------<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">if nargin < 1<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> % En caso de no especificarse argumentos se "busca" un elemento del<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> % tipo uitable y se asigna como archivo de salida a html/utitled.html<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> hTab = findobj('type','uitable');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> if ~isempty(hTab)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> filename = 'html/untitled.html';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> else<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> error('No existe elemento uitable disponible');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">if ~strcmp(get(hTab,'type'),'uitable')<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> % Verificando que la referencia sea tipo "uitable"<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> error('La referencia debe ser de tipo uitable');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% ========================== OPCIONES ===================================<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">fields_opts = {'PageTitle', 'Sin título',;<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> 'TableTitle', '<b>Tabla 1</b>';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> 'BgColor', '#F0F0F0';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> 'FontName', 'DejaVu Sans Mono';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> 'BorderWidth', '2';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> 'FontColor', '#0000F0'};<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">if nargin == 3 && isstruct(opts)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> for k = 1:size(fields_opts,1)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> if ~isfield(opts,fields_opts{k,1})<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> opts = setfield(opts,fields_opts{k,1},fields_opts{k,2});<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">else<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> opts = cell2struct(fields_opts(:,2),fields_opts(:,1),1);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% ======================= PROPIEDADES DE LA TABLA ======================<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">X = get(hTab,'Data');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">colnames = get(hTab,'ColumnName');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">[nrows, ncols] = size(X);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% ========================= PLANTILLAS ================================<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">COL_TEMP = '<TD>_col_</TD>';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">ROW_TEMP = '<TR>_row_</TR>';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">HEADER_TEMP = '<TH bgcolor=#DCDCFF>_header_</TH>';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">HTML_TEMP = ['<html><head><title>_pagetitle_</title></head><body><font face="_fontname_">',...<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> '<table border=_borderwidth_ bordercolor=#000000 cellspacing=5 cellpadding=5 bgcolor=_bgcolor_>',...<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> ' <caption>_tabletitle_</caption> _table_ </table></font> _footnote_ </body></html>'];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">FOOT_TEMP = ['<br><br><br><font face="Arial Narrow" color=#C0C0C0 size=2>',...<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> 'Published by: <cite>table2html</cite></font>'];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% ========================== ENCABEZADOS =============================<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">if strcmp(colnames,'numbered')<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> colnames = repmat('untitled|',1,ncols);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> remain = colnames;<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> colnames = {};<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> while 1<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> [str,remain]=strtok(remain,'|');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> if isempty(str),break,end;<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> colnames=[colnames str];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">rstr = WriteHeaders(colnames);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">WriteTable(rstr);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">web(filename,'-browser');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">% =====================================================<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> function rstr = WriteHeaders(headers)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> rstr = '';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> for k = 1:ncols<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> rstr=[rstr,strrep(HEADER_TEMP,'_header_',headers{k})];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> function WriteTable(rstr)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> [path_,~,~] = fileparts(filename);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> if ~isempty(path_)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> if ~isdir(path_)<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> mkdir(path_);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> <o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> fid=fopen(filename,'w');<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> for i=1:nrows<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> cstr='';<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> for j=1:ncols<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> if isa(X,'cell')<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> cstr = [cstr,strrep(COL_TEMP,'_col_',num2str(X{i,j})),' '];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> else<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> cstr = [cstr,strrep(COL_TEMP,'_col_',num2str(X(i,j))),' '];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> rstr = [rstr,strrep(ROW_TEMP,'_row_',cstr)];<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> WEB_PAGE = strrep(HTML_TEMP,'_table_',rstr);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> WEB_PAGE = regexprep(WEB_PAGE,{'_footnote_','_bgcolor_',...<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> '_fontname_','_borderwidth_','_tabletitle_','_pagetitle_','_fontcolor_'},...<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> {FOOT_TEMP,opts.BgColor,opts.FontName,opts.BorderWidth,...<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> opts.TableTitle,opts.PageTitle,opts.FontColor});<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> fprintf(fid,'%s',WEB_PAGE);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> fclose(fid);<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;"> end<o:p></o:p></span></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><br /></div><div class="Code" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; padding: 0cm;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt;">end<o:p></o:p></span></div></div><br />Para una referencia más completa con algunos ejemplos/test de la función table2html puede revisar el siguiente enlace:<br /><br /><a href="https://github.com/JorgeDeLosSantos/matlab-gui-codes/tree/master/table2html">table2html (GitHub)</a>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-75761961809013011472014-12-03T09:22:00.000-06:002016-03-21T22:38:50.700-06:00Intercambiar filas y columnas de una matriz en MATLAB<div style="text-align: justify;">El hecho de intercambiar filas y columnas de una matriz suele ser un tema muy importante en álgebra lineal. Aquí vamos a explicar con ejemplos cómo lograr esto mediante la indexación de matrices utilizando el operador dos puntos.</div><br />Para ejemplificar vamos a utilizar la matriz A, definida por:<br /><br />$$A=\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}$$<br /><br />Creando la matriz en MATLAB:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> A=[1,2,3;4,5,6;7,8,9]</span><br /><span style="font-family: Courier New, Courier, monospace;">A =</span><br /><span style="font-family: Courier New, Courier, monospace;"> 1 2 3</span><br /><span style="font-family: Courier New, Courier, monospace;"> 4 5 6</span><br /><span style="font-family: Courier New, Courier, monospace;"> 7 8 9</span><br /><br /><b><span style="font-size: large;">Intercambiar filas</span></b><br /><br />Suponga que se pide intercambiar las filas 1 y 2, entonces se procedería como sigue:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> A([1 2],:)=A([2 1],:)</span><br /><span style="font-family: Courier New, Courier, monospace;">A =</span><br /><span style="font-family: Courier New, Courier, monospace;"> 4 5 6</span><br /><span style="font-family: Courier New, Courier, monospace;"> 1 2 3</span><br /><span style="font-family: Courier New, Courier, monospace;"> 7 8 9</span><br /><br />Básicamente le estamos "diciendo" a MATLAB que de la matriz A sustituya todas las columnas de las filas 1 y 2 por las filas 2 y 1, es decir, "invirtiendo" el orden.<br /><br /><br /><span style="font-size: large;"><b>Intercambiar columnas</b></span><br /><br />La lógica usada es prácticamente la misma que en el caso anterior, con la única diferencia que el operador dos puntos lo utilizaremos en el índice de las filas. Por ejemplo, de la matriz A original vamos a intercambiar las filas 2 y 3:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> A(:,[2 3])=A(:,[3 2])</span><br /><span style="font-family: Courier New, Courier, monospace;">A =</span><br /><span style="font-family: Courier New, Courier, monospace;"> 1 3 2</span><br /><span style="font-family: Courier New, Courier, monospace;"> 4 6 5</span><br /><span style="font-family: Courier New, Courier, monospace;"> 7 9 8</span><br /><br /><br /><b><span style="font-size: large;">Definiendo funciones propias</span></b><br /><br />Finalmente, si lo anterior le parece un poco confuso, puede utilizar las siguientes funciones: <span style="font-family: Courier New, Courier, monospace;">swaprows</span> y <span style="font-family: Courier New, Courier, monospace;">swapcols</span>, que intercambian filas y columnas respectivamente:<br /><br /><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> X = swaprows(A,m1,m2)</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">X = A;</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">X(m1,:) = A(m2,:);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">X(m2,:) = A(m1,:);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">end</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div></div><br /><div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> X = swapcols(A,n1,n2)</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">X = A;</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">X(:,n1) = A(:,n2);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">X(:,n2) = A(:,n1);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">end</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div></div><br />La sintaxis para ambas es similar, simplemente necesita pasar como argumento la matriz y las filas y/o columnas a intercambiar de posición. Desde luego las funciones anteriores no están incluidas en MATLAB por defecto, por lo que habrá de colocarlas a su directorio de trabajo o bien añadirlas al PATH de MATLAB.<br /><br /><br />Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com7tag:blogger.com,1999:blog-6491678271581908753.post-7954471244237471632014-11-24T22:00:00.000-06:002016-03-21T22:38:50.712-06:00GUIOOD Toolbox, desarrollando GUIs utilizando el paradigma de la POO<div style="text-align: justify;">GUIOOD Toolbox (Graphical User Interface with Object-Oriented Design) es un conjunto de clases implementadas en MATLAB cuyo objetivo es desarrollar interfaces gráficas de usuario utilizando una sintaxis similar a la de Java, es decir, con el paradigma de la programación orientada a objetos. </div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Básicamente, GUIOOD se está desarrollando para funcionar como un wrapper de las GUIs ordinarias en MATLAB. Se pretende que la programación de GUIs sea más rápida y sencilla. Desde luego que habrá de considerarse el hecho de que "debajo" hay una interfaz gráfica ordinaria, por lo cual la cantidad de controles gráficos disponibles serán los mismos, con algunos añadidos utilizando la librería swing de Java.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-size: large;"><b>¿Qué es lo nuevo?</b></span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Desde luego, la forma de programar. Todos los elementos gráficos serán objetos de una determinada clase y tendrán métodos para modificar sus atributos. Por ejemplo para crear una ventana el código correspondiente sería algo como esto:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">app = Frame('Ventana 1', [300 200]);</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">app.SetColor('r');</span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Ha de mencionarse que el nombre de algunos controles gráficos han sido sustituidos por su equivalente en Java, además que muchos métodos guardan similitud con dicho lenguaje y en otros casos con la librería wxPython. La siguiente es una tabla que muestra la equivalencia de notación entre las GUIs MATLAB ordinarias y el GUIOOD Toolbox:</div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj21GFgmEGqtqRXiWBYBSwfrTSJ8Uwi0dBQQuw6EYaPlgAkvICwuW3AF_euSpNPRTt4JdVtYKvszRReQRXerrzjGxF1IUK5ug4zZcLW4E3GMSD47i7f8otffOVD4lPJVDkn-rMjLflw4VIB/s1600/Captura.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj21GFgmEGqtqRXiWBYBSwfrTSJ8Uwi0dBQQuw6EYaPlgAkvICwuW3AF_euSpNPRTt4JdVtYKvszRReQRXerrzjGxF1IUK5ug4zZcLW4E3GMSD47i7f8otffOVD4lPJVDkn-rMjLflw4VIB/s1600/Captura.PNG" height="246" width="320" /></a></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Como puede verse en la tabla, GUIOOD añade algunos controles gráficos no disponibles en MATLAB. El Canvas es un axes "modificado" que se espera utilizar para dibujos 2D como circulos, rectangulos, elipses y otras figuras de geometría simple, en principio. El PasswordField es similar a una entrada de texto editable, con la diferencia que permite "esconder" los caracteres que en el se introducen, es decir, un campo de contraseñas, que se ha extendido del componente JPasswordField de Java. El Spinner de manera similar se ha extendido del componente JSpinner de Java. Y el AboutDialog es un cuadro de diálogo que contiene información acerca de la GUI, la idea y notación se ha tomado del componente del mismo nombre de la librería wxPython. Es muy probable que se añadan otros controles que puedan resultar útiles, desde luego "tomándolos prestados" de Java.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Otra parte interesante de GUIOOD Toolbox es que dispone de manejadores de posiciones o de distribución de componentes (layouts), los cuales ahorran tiempo significativo, dado que no hay necesidad de indicar las posiciones de los objetos gráficos de forma explícita. Los algoritmos de posicionamiento están en fase de desarrollo, siendo funcionales, pero con algunos detalles en cuanto al orden en que habrán de agregarse los componentes. Se dispone de 3 layouts: grid, vertical y horizontal. El primero distribuye los objetos utilizando filas y columnas como referencia, y el vertical y horizontal los distribuyen como se esperaría, dado el nombre.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span style="font-size: large;">Utilidades añadidas</span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">GUIOOD permite exportar el contenido de una Table MATLAB a una tabla en HTML, y también a una hoja de cálculo Microsoft Excel.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">El contenido de un Axes puede exportarse como imagen PNG, como un PDF, o incrustarla en un archivo HTML.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span style="font-size: large;">Estado del proyecto</span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">El proyecto GUIOOD Toolbox comenzó a desarrollarse a principios de Noviembre de 2014, encontrándose ahora en una etapa muy temprana. Existen muchos detalles por agregar, como dar un mayor soporte al manejo de los eventos, un manejo de errores/excepciones un poco más personalizado, refinar los algoritmos de posicionamiento, escribir la documentación, y sobre todo mucho "testeo" del código. </div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">El plan inicial contempla un desarrollo durante seis meses. Por lo cual, se esperaría que para Mayo de 2015 pueda estar disponible una versión preliminar. ¿Por qué seis meses?, bueno, el calendario incluye muchos días festivos en este lapso.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-size: large;"><b>Un ejemplo preeliminar (funcional)</b></span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">A continuación se expone un fragmento de código totalmente funcional, y que deja ver más o menos la idea que se sigue y lo que se espera obtener:</div><div style="text-align: justify;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> MiniCalc</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% MiniCalc / Demo for GUIOOD Toolbox</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">% </span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">% Author: Jorge De Los Santos</span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">% Version: 0.1.0</span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% E-mail: delossantosmfq@gmail.com</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% License: MIT License</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">app = Frame(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Mini Calculadora'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">,[220 100]);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">app.SetLayout(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'grid'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">,5,3,1); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Set main layout: grid. 5 rows and 3 columns</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p1 = Panel(); </span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p2 = Panel();</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p3 = Panel();</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">app.AddMany(p1,p2,p3); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Add many panels to Frame (main app)</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Labels and TextFields</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">lb1 = Label(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'# 1'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">lb2 = Label(</span><span style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">'# 2'</span><span style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">num1 = TextField();</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">num2 = TextField();</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p1.AddMany(num1,lb1); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Add controls to Panel p1</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p2.AddMany(num2,lb2); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Add controls to Panel p2</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Buttons</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt1 = Button(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'+'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt2 = Button(</span><span style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">'-'</span><span style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt3 = Button(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'*'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt4 = Button(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'/'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p3.AddMany(bt1,bt2,bt3,bt4); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Add buttons to panel p3</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">p3.SetLayout(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'horizontal'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">,2); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Set layout for p3, horizontal and two controls</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt1.SetCallback(@calcular_fcn); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Set callback for buttons </span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt2.SetCallback(@calcular_fcn);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt3.SetCallback(@calcular_fcn);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">bt4.SetCallback(@calcular_fcn);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> calcular_fcn(~,~,obj)</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> a = num1.GetText(); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Get value of "num1" Label</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> b = num2.GetText(); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Get value of "num2" Label</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> oper = obj.GetText(); </span><span lang="EN-US" style="color: forestgreen; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">% Get the operator of current Button clicked</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> MessageBox([</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Resultado = '</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">,num2str(eval([a,oper,b]))],</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; font-size: 10.0pt; mso-ansi-language: EN-US;">'GUIOOD'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono'; font-size: 10pt;"> </span><span style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">end</span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><br /></div><div style="text-align: justify;"> </div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "DejaVu Sans Mono"; font-size: 10.0pt;">end</span><span style="font-family: "DejaVu Sans Mono"; font-size: 12.0pt;"><o:p></o:p></span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRrpftU_NOAvGa4wbaopbigm2B8ocx1sfQbyx2Jtq6ShjLsQChmYXtixSFv8Vv4XCihDV-AwymDBsY53fMmFy3NmVb_-TuxdSZeYzl5vufK9EGUCLCcH7OxNIxnb2uA1zeO3CnZRXzdhC7/s1600/Captura.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRrpftU_NOAvGa4wbaopbigm2B8ocx1sfQbyx2Jtq6ShjLsQChmYXtixSFv8Vv4XCihDV-AwymDBsY53fMmFy3NmVb_-TuxdSZeYzl5vufK9EGUCLCcH7OxNIxnb2uA1zeO3CnZRXzdhC7/s1600/Captura.PNG" /></a></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Si la GUI le parece "rara", no os preocupéis, cuestiones de temas del SO en que se ejecutó esta prueba.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Cualquier comentario o sugerencia es siempre bienvenida. Y si desea colaborar con el proyecto no dude en contactar a los correos del blog (matlabtyp@gmail.com).</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-26733937572679114822014-11-17T12:56:00.000-06:002016-03-21T22:38:50.622-06:00Ejecutar comandos del sistema operativo en MATLAB<div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Esta entrada tiene como objetivo mostrar la utilización de comandos nativos del sistema operativo desde el entorno de MATLAB. Pero ¿para qué utilizar comandos del SO?, para muchas cosas desde luego, podría necesitarse para ejecutar un script escrito en otro lenguaje de programación (Perl, Python,…), configurar variables del sistema, compilar y/o ejecutar un código fuente, entre otras muchas tareas.<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">MATLAB proporciona la función system que permite ejecutar cualquier instrucción soportada por el SO, la cual debe pasarse como un string, por ejemplo:<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;">>> system('cd')<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;">C:\Users\User\Documents\MATLAB\MATLAB TYP<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Courier New";">ans =<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Courier New";"> 0<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Courier New";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">En lo anterior cd es un comando del sistema operativo que devuelve el directorio actual (tal como lo hace la función cd de MATLAB). Note que además de la cadena esperada se devuelve un valor cero guardado en la variable ans, esto sirve como identificador de status, indicando, en este caso, que el comando ha sido ejecutado de forma satisfactoria.<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Existe la alternativa de colocar un ampersand (&) al final de la instrucción para indicar que la respuesta del sistema se mostrará en una consola o terminal nativa, para el caso anterior sería:<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal"><span style="font-family: "Courier New";">>> system('cd&')<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Courier New";">ans =<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Courier New";"> 0<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Courier New";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Como se observa, simplemente se devuelve el status en el Command Window e inmediatamente se abre una consola mostrando el resultado de evaluar el comando del SO.<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Para Microsoft Windows o sistemas basados en DOS existe la alternativa de usar el símbolo de exclamación de apertura (!) antecediendo a un comando, siguiendo con el mismo ejemplo:<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="tab-stops: 64.5pt; text-align: justify;"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;">>> !cd <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;">C:\Users\User\Documents\MATLAB\MATLAB TYP <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">En este caso no se devuelve un status, lo cual nos llevaría a sugerir que si se requiere mayor robustez de código entonces habría que optar por el uso de la función system.<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><br /></div><div class="MsoNormal" style="text-align: justify;"><b><span style="color: #0070c0; font-family: "DejaVu Sans","sans-serif"; font-size: 12.0pt; line-height: 115%; mso-bidi-font-size: 11.0pt;">Abriendo programas de Microsoft Windows…<o:p></o:p></span></b></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Utilizando system podemos acceder a programas nativos de Windows (Paint, Bloc de Notas, Recorte de pantalla, …). Para ello basta con pasar como argumento el nombre del programa, por ejemplo para abrir el Bloc de Notas:<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">>> system('notepad&');</span><span style="font-family: DejaVu Sans, sans-serif;"><o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">O para la herramienta Recortes (Windows 7):<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="EN-US"><span style="font-family: Courier New, Courier, monospace;">>> system('SnippingTool&');</span><span style="font-family: DejaVu Sans, sans-serif;"><o:p></o:p></span></span></div><div class="MsoNormal" style="text-align: justify;"><br /></div><div class="MsoNormal" style="text-align: justify;"><span lang="EN-US" style="font-family: "DejaVu Sans","sans-serif"; mso-ansi-language: EN-US;"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><b><span lang="EN-US" style="color: #0070c0; font-family: "DejaVu Sans","sans-serif"; font-size: 12.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-size: 11.0pt;">Ejecutando un script Python…<o:p></o:p></span></b></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Normalmente para ejecutar un script desarrollado en Python debería teclearse en una consola (o terminal) algo similar a esto:<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "Courier New";">> python nombre_script.py<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "Courier New";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Obviando el hecho de que estamos situados en la carpeta correspondiente para nuestro script python. <o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Usando la función system esto debería funcionar de la misma manera que se explicó anteriormente, así pues en MATLAB habría de introducirse lo siguiente:<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;">>> system('python ejemplo.py&')<o:p></o:p></span></div><div class="MsoNormal" style="text-align: justify;"><span lang="EN-US" style="font-family: "Courier New"; mso-ansi-language: EN-US;"><br /></span></div><div class="MsoNormal" style="text-align: justify;"><span style="font-family: "DejaVu Sans","sans-serif";">Donde ejemplo.py es el nombre del script. En este caso sí que es muy necesario adicionar el ampersand al final de la instrucción, para evitar cualquier tipo de incompatibilidad entre las salidas y entradas estándar de MATLAB y Python.<o:p></o:p></span></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-66215819784142176342014-11-15T00:12:00.000-06:002016-03-21T22:38:50.678-06:00Modificando el color de línea de una gráfica generada con ezplot<div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">La función ezplot es útil para trazar gráficas mediante una expresión definida simbólicamente o mediante una cadena de caracteres, lo cual, generalmente, facilita el trazo de las gráficas. Aunque lo más común es que un usuario de MATLAB comience utilizando la función plot para esta tarea, y con ello estará 'acostumbrado' a la posibilidad de incluir especificaciones de estilo, color y grosor de linea. Por ejemplo la siguiente instrucción trazará una gráfica de los vectores x e y utilizando una línea roja punteada:</span></div><div style="text-align: justify;"><br /></div><span style="font-family: Courier New, Courier, monospace;">plot(x,y,'r--');</span><br /><br /><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">No obstante, si se intenta hacer lo mismo con ezplot, MATLAB devolverá un error. La sintaxis más usual de ezplot es:</span></div><br /><span style="font-family: Courier New, Courier, monospace;">ezplot('f(x)', [a,b]);</span><br /><br /><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">Siendo <b>a</b> y <b>b</b> los extremos del intervalo a graficar. Ahora, se queremos personalizar la gráfica tendremos que hacer uso de la referencia (handle) a la linea graficada, para ello basta con asignar a una variable la instrucción de graficado, por ejemplo:</span></div><br /><span style="font-family: 'Courier New', Courier, monospace;">hL = ezplot('f(x)', [a,b]);</span><br /><br /><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">Con esta referencia guardada en la variable <b>hL</b> es posible utilizar la función set para modificar las propiedades de la linea. Véase el ejemplo siguiente:</span></div><div style="text-align: justify;"><br /></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">hL = ezplot(</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'sin(x)'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">,[0 10]);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div style="text-align: justify;"></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">set(hL,</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'Color'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'r'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'LineStyle'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "DejaVu Sans Mono"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'--'</span><span lang="EN-US" style="font-family: 'DejaVu Sans Mono';">);</span><span lang="EN-US" style="font-family: "DejaVu Sans Mono"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPtIYgP1iGGg66R1sgTkb0pm6BOxT0zqHwDAp7UbQ2QZUY_EZjmV5R6m3J7VsozbFgD3iyTL_Uq86dqRKLInm1VbhsA31HL40BZepXg3IfGh8V7kT0idF2K1Zk3dordbd5GWrUlEjvoDo6/s1600/Captura.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPtIYgP1iGGg66R1sgTkb0pm6BOxT0zqHwDAp7UbQ2QZUY_EZjmV5R6m3J7VsozbFgD3iyTL_Uq86dqRKLInm1VbhsA31HL40BZepXg3IfGh8V7kT0idF2K1Zk3dordbd5GWrUlEjvoDo6/s1600/Captura.PNG" height="355" width="400" /></a></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com1tag:blogger.com,1999:blog-6491678271581908753.post-27531751737283137212014-08-20T22:10:00.000-05:002016-03-21T22:38:50.625-06:00Calculo de un determinante mediante recursividad en MATLAB<div style="text-align: justify;">El calculo de un determinante mediante recursividad o formalmente conocido como <a href="http://es.wikipedia.org/wiki/Teorema_de_Laplace">Teorema o Desarrollo de Laplace</a>, consiste en calcular el determinante de una matriz cuadrada de $nxn$ mediante una descomposición en suma de determinantes menores, es decir, ir reduciendo en $n-1$ dimensiones. El desarrollo se puede hacer por filas o columnas.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">La función recursiva para calcular el determinante utilizando el desarrollo en la primera fila puede expresarse como sigue:</div><div style="text-align: justify;"><br /></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://upload.wikimedia.org/math/5/e/5/5e50d7dbc2d2e98502f7fe816db93c3a.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://upload.wikimedia.org/math/5/e/5/5e50d7dbc2d2e98502f7fe816db93c3a.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Fuente: Wikipedia</td></tr></tbody></table><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Donde $a_{1,k}$ hace referencia al elemento ubicado en la primera fila y k-ésima columna, y $\alpha_{1,k}$ es el adjunto del elemento mencionado anteriormente.</div><br />Basado en la referencia anterior se implementó la siguiente función en MATLAB:<br /><br /><br /><div style="text-align: justify;"><br /><script src="http://pastebin.com/embed_js.php?i=Bux6pbYX"></script> <br />Ahora veamos un poco más detallado lo que implica cada línea de la función anterior: en la línea 2 se crea una vector idx cuyos valores son los números en el intervalo <b>[1 n]</b> y que servirá para obtener, mediante un <i>masking</i>, los indices en fila y columna pertenecientes al adjunto correspondiente (véase linea 7 y 8). El ciclo for se implementa desde un valor unitario hasta el número de filas/columnas de la matriz de entrada <b>X, </b>y enseguida con la sentencia if se comprueba si la matriz de entrada es de dimensiones unitarias (con lo cual se retorna la entrada misma) o bien si es de dimensiones mayores, con lo cual se implementa el algoritmo recursivo. Finalmente, habrán de sumarse todos los valores obtenidos en cada iteración del ciclo for, para ello se utiliza la función <span style="font-family: Courier New, Courier, monospace;">sum</span>.</div><div style="text-align: justify;"><br /></div><br /><b><span style="font-size: large;">El costo de la recursividad</span></b><br /><br /><div style="text-align: justify;">Por regla general, un algoritmo recursivo suele ser lento en ejecución. Por lo cual siempre es recomendable buscar o implementar otras técnicas de programación. En este caso, el ejemplo que hemos dado es puramente con fines didácticos, pero para mostrar un "poco" de lo ya dicho he decido "contar" el número de "llamadas" que se hacen a la función durante la ejecución para matrices de diversos tamaños. En la siguiente tabla se muestran las "llamadas" correspondientes para una matriz de $nxn$:</div><div style="text-align: center;"><br /></div><div style="text-align: center;"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableLightList" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"> <tbody><tr> <td style="background: white; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><span style="color: #1f497d; font-family: "Impact","sans-serif"; mso-bidi-font-weight: bold; mso-themecolor: text2;">Dimensión de la matriz<o:p></o:p></span></div></td> <td style="background: white; border-left: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><span style="color: #1f497d; font-family: "Impact","sans-serif"; mso-bidi-font-weight: bold; mso-themecolor: text2;">Número de llamadas<o:p></o:p></span></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>1<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>1<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>2<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>3<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>3<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>10<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>4<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>41<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>5<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>206<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>6<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>1237<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>7<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>8660<o:p></o:p></b></div></td> </tr><tr> <td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 125.9pt;" valign="top" width="168"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>8<o:p></o:p></b></div></td> <td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 4.0cm;" valign="top" width="151"> <div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b>69281<o:p></o:p></b></div></td> </tr></tbody></table></div><div style="text-align: justify;"><br />Como se observa el número de "llamadas" a la función crece de forma exponencial, lo cual se traduce en un gasto computacional considerable cuando las dimensiones de la matriz son mayores a un par de decenas e incluso menos. Se adjunta una gráfica correspondiente a la tabla anterior.</div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCWHGX_3T3BVlBoadxsW_auBldXeK5ikwzTowr5KXSpyL750IsHqaYCAF4f-YQrIIEvBjtHc3P6PgelL1xfuMCvzTeSRugHhNy3TR05EZS6IHcl3ebPgYLPgm9TQBOqzVMqV18diPlM1wM/s1600/recur.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCWHGX_3T3BVlBoadxsW_auBldXeK5ikwzTowr5KXSpyL750IsHqaYCAF4f-YQrIIEvBjtHc3P6PgelL1xfuMCvzTeSRugHhNy3TR05EZS6IHcl3ebPgYLPgm9TQBOqzVMqV18diPlM1wM/s1600/recur.PNG" height="285" width="320" /></a></div><br />Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-54104322851692466952014-08-12T17:16:00.000-05:002016-03-21T22:38:50.657-06:00Sentencia continue en MATLABLa sentencia continue es útil para controlar las ejecuciones dentro de un bucle, permite ignorar cualquier instrucción posterior al llamado de esta y continuar con el siguiente ciclo. Por ejemplo, véase el siguiente código:<br /><br /><div style="background: #EEECE1; border: solid windowtext 1.0pt; mso-background-themecolor: background2; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">for</span><span style="font-family: 'Courier New';"> i=1:5</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';"> disp(i);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';"> </span><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">continue</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';"> disp(i^2);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><br />Si ejecutamos lo anterior MATLAB imprimirá en pantalla los valores del 1 al 5, pero no llegará a "imprimir" los valores resultantes de elevarlos al cuadrado. Se preguntará el lector, esto para qué me sirve si pude no escribir las instrucciones posteriores o bien comentarlas para evitar su ejecución, y toda la razón tendrá, pero, ahora veamos un ejemplo más significativo y en el cual puede resultar más interesante la utilidad de continue:<br /><br /><div style="background: #EEECE1; border: solid windowtext 1.0pt; mso-background-themecolor: background2; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">for</span><span lang="EN-US" style="font-family: 'Courier New';"> i=1:5</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">if</span><span lang="EN-US" style="font-family: 'Courier New';">rem(i,2)==0</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';"> </span><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">continue</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';"> </span><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';"> disp(i);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><br />Revisemos lo anterior: al "correr" el script MATLAB nos devolverá en pantalla todos los números impares en el intervalo de ejecución, dado que si se cumple la condición de que el residuo de la división entera $i/2$ es nulo entonces ignorará la instrucción disp que se encuentra enseguida y pasará a ejecutarse la siguiente iteración.<br /><br />La referencia "online" que proporciona MathWorks muestra un ejemplo del conteo de líneas de un archivo de texto, en el cual la sentencia continue se utiliza para evitar adicionar aquellas líneas en blanco. Puede ver el ejemplo en el siguiente link:<br /><br /><a href="http://www.mathworks.com/help/matlab/ref/continue.html">Sentencia continue </a>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-77637649819454085002014-07-24T07:24:00.000-05:002016-03-21T22:38:50.710-06:00Leer y mostrar imágenes con MATLAB<div style="text-align: justify;">De forma habitual, se utilizan las funciones del Image Processing Toolbox de MATLAB para importar, procesar y visualizar imágenes, más concretamente las funciones imread e imshow para leer y mostrar imágenes respectivamente. Pero además de las anteriores, puede utilizarse algunas funciones que forman parte del núcleo de MATLAB para dichas tareas, tales como importdata e image / imagesc, evidentemente pueden presentar ciertos inconvenientes, pero representan una alternativa en el caso de no contar con el toolbox requerido.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span style="font-size: large;">Leer una imagen con <span style="font-family: Courier New, Courier, monospace;">imread</span></span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">La sintaxis de la función imread es muy sencilla, a saber:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">>> imread('nombre_img','formato');</span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Donde nombre_img es el nombre de la imagen o bien la ruta completa de la imagen en el caso que no se encuentre en el Current Folder, formato es justamente eso: el tipo de imagen que vamos a leer (PNG, JPG, GIF, TIFF, etc...), es común omitir el segundo argumento e incluir, claro, la extensión del archivo en el nombre del mismo. Para ejemplificar utilizaré una imagen cuyo nombre es "img", en formato jpg y que se encuentra almacenada en el directorio actual de trabajo, luego para leer la imagen se tendría que hacer lo que a continuación se muestra:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">>> X=imread('img.jpg');</span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Al teclear la instrucción anterior MATLAB crea una matriz X en la cual se guarda la información de cada uno de los píxeles que componen la imagen. Podemos verificarlo utilizando el comando <span style="font-family: Courier New, Courier, monospace;">whos</span> como sigue:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">>> whos X</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"> Name Size Bytes Class Attributes</span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;"> X 300x400x3 360000 uint8 </span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Revisando lo que MATLAB nos devuelve podemos identificar que la matriz creada está compuesta de 300 filas, 400 columnas y tres capas o planos correspondientes al modelo de color RGB (Red, Green, Blue), es decir, cada capa corresponde a la intensidad de cada uno de los colores. Además, la clase de datos utilizados son uint8 (entero sin signo de 8 bits) cuyo rango es de 0 a 255.<br /><br /><br /><b><span style="font-size: large;">Mostrar una imagen con <span style="font-family: Courier New, Courier, monospace;">imshow</span></span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Una vez se ha leído y almacenado la imagen podemos utilizar la función imshow para visualizarla, la sintaxis de esta función es:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> imshow(IMG);</span><br /><br />Donde IMG es la matriz en la cual se ha guardado la información referente a la imagen. Para nuestro caso:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> imshow(X);</span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHFovWROYv8zFnodE_Ab51mJLZegtnUKbI6h6SgvOTDS6fRZRdYussi19K76lR3VL-UtMW1J9ld4LCZbiJTdL1yDgAg7vtDBGBNbMiukMyc44E3ui9_6GNZ_TPaBBY4kcX4gSctAKZN36L/s1600/imagen.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHFovWROYv8zFnodE_Ab51mJLZegtnUKbI6h6SgvOTDS6fRZRdYussi19K76lR3VL-UtMW1J9ld4LCZbiJTdL1yDgAg7vtDBGBNbMiukMyc44E3ui9_6GNZ_TPaBBY4kcX4gSctAKZN36L/s1600/imagen.PNG" height="328" width="400" /></a></div><br /><br /><span style="font-size: large;"><b>Utilizando <span style="font-family: Courier New, Courier, monospace;">importdata e imagesc</span></b></span><br /><br />Además de imread, es posible leer una imagen utilizando la función <span style="font-family: Courier New, Courier, monospace;"><a href="http://www.mathworks.com/help/matlab/ref/importdata.html">importdata</a></span>, la sintaxis es:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> X=importdata('nombre_img');</span><br /><br />Para el ejemplo que hemos utilizado:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> X=importdata('img.jpg');</span><br /><br />Una vez almacenada la imagen podemos utilizar la función imagesc para mostrar la imagen:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> imagesc(X);</span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8PavuNrK3qqEADfFGaIqiYK7kGduLPfdYNNkw-CTYFA8BBa2eapam9lO_6_1nQWWzjXanARULVQN0AhNSWPe0XoHa3NfW4-OeFWmo6cAvY-81_7UxzPkgqvKuD2Idj3CVi1e_AKroZx8E/s1600/imagen.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8PavuNrK3qqEADfFGaIqiYK7kGduLPfdYNNkw-CTYFA8BBa2eapam9lO_6_1nQWWzjXanARULVQN0AhNSWPe0XoHa3NfW4-OeFWmo6cAvY-81_7UxzPkgqvKuD2Idj3CVi1e_AKroZx8E/s1600/imagen.PNG" height="355" width="400" /></a></div><br /><br />Y como tal, el objetivo de esta entrada era simplemente adquirir y visualizar las imágenes. En posteriores entradas se hará referencia a algunas operaciones básicas que pueden aplicarse a una imagen, o mejor dicho, a la matriz que guarda la información de la misma.<br /><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com9tag:blogger.com,1999:blog-6491678271581908753.post-62288167624554404352014-07-10T15:35:00.000-05:002016-03-21T22:38:50.667-06:00Graficar inecuaciones / desigualdades en MATLABUna inecuación es una desigualdad algebraica que contiene una o más incógnitas, ejemplos de estas son las siguientes:<br /><br />$$x^2+y^2>2$$<br />$$x+3>y$$<br />$$x^3+7<1$$<br /><br />MATLAB no tiene soporte nativo para graficar desigualdades, pero evidentemente pueden implementarse soluciones mediante comparadores que evalúen los valores tomados por una cierta expresión en una región especificada. La siguiente función llamada <span style="font-family: Courier New, Courier, monospace;">inecgraf</span> permite llevar a cabo dicha tarea:<br /><br /><div style="background: #EEECE1; border: solid windowtext 1.0pt; mso-background-themecolor: background2; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> varargout = inecgraf(I,R)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% Grafica una desigualdad (inecuación) en un rango</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% especificado.</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">%</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% Argumentos de entrada:</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% I - Inecuación</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% R - Rango en el cual se trazará la</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% gráfica.</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">%</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% Argumentos de salida:</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% h - Si se especifica un argumento </span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% salida, la función devuelve un </span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% array de handles que le permite</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% modificar las propiedades de la</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% gráfica de salida. (Véase ejemplos).</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">%</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% Ejemplos: </span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% >> inecgraf('x.^2+y.^2<10',[-5 5]);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% >> h = inecgraf('y<x+3',[0 10]);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">% >> set(h,'color','r','MarkerSize',5);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% </span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt;">% || Por: Jorge De Los Santos ||</span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: forestgreen; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">% || Rev. 1.0 || Fecha: 06/05/14 ||</span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><br /></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">set(gca,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'NextPlot'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'add'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">axis([R(1) R(2) R(1) R(2)]);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">dd=(R(2)-R(1))/50;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">[x,y]=meshgrid(R(1):dd:R(2));</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">[f,c]=find(eval(I));</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">h=zeros(1,length(f));</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">for</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> i=1:length(f)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> h(i)=plot(x(f(i),c(i)),y(f(i),c(i)),</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'b*'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'MarkerSize'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,2);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">end</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">if</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> nargout==1</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> varargout{1}=h;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div></div><br /><br />Las instrucciones de uso se muestran en la descripción de la función, enseguida se muestran los ejemplos obtenidos para las inecuaciones que se indican:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> inecgraf('y>x.^2-2',[-5 5]);</span><br /><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnN8zEMlvf5nNkPWPI0AN0tT0jAUnSBOecwex3P1zyaLQNfvfVomhAh3xYyLE95ms4re_32PcCAbSsd1IITt3n8qgd9jt58U1K5OmsrEhJVy1TF47ScnUuEqBpQYD6IWpXMhAk-YYx920H/s1600/ineq2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnN8zEMlvf5nNkPWPI0AN0tT0jAUnSBOecwex3P1zyaLQNfvfVomhAh3xYyLE95ms4re_32PcCAbSsd1IITt3n8qgd9jt58U1K5OmsrEhJVy1TF47ScnUuEqBpQYD6IWpXMhAk-YYx920H/s1600/ineq2.PNG" height="353" width="400" /></a></div><br /><br /><span style="font-family: Courier New, Courier, monospace;">>> inecgraf('x.^2+y.^2>5',[-5 5]);</span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC5UZXYy9dCAq-98jQYCeCDzseOLHk6BJnLiFTB3Go3cez51jwG4U0s_TM0sdF4N5tbxfFNJy1k2p84QqTljNUOCNF4FyjWQHZrN5wsWbwDt6hRcBUD3DYHbcShN4iggcOtbCaZ710pLyq/s1600/ineq1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC5UZXYy9dCAq-98jQYCeCDzseOLHk6BJnLiFTB3Go3cez51jwG4U0s_TM0sdF4N5tbxfFNJy1k2p84QqTljNUOCNF4FyjWQHZrN5wsWbwDt6hRcBUD3DYHbcShN4iggcOtbCaZ710pLyq/s1600/ineq1.PNG" height="355" width="400" /></a></div><br /><br /><br />Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-21414873020431479392014-07-09T01:19:00.000-05:002016-03-21T22:38:50.605-06:00¿ MATLAB o Maple ?<div style="text-align: justify;">¿Por qué MATLAB?, ¿Por qué Maple? o ¿Cuando utilizar MATLAB, o Maple?, son quizá algunas de las interrogantes respecto a este "dilema" que a más de uno le han surgido. </div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Para comenzar, ambos programas fueron desarrollados allá por la década de los 80's: Maple en 1981 en Canadá y MATLAB en 1984 en EEUU. Orientados ambos a resolver problemas de matemáticas e ingeniería, no obstante, existen diferencias muy notorias: Maple está más especializado en el área del cálculo simbólico y el álgebra computacional, y MATLAB en la computación numérica y el desarrollo de modelos y simulaciones para ingeniería.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">A experiencia propia, cuando ingresé al nivel universitario hace unos años, me vi pronto en la necesidad (como casi todos, imagino) de buscar un software que me permitiera hacer más llevaderos mis cursos de matemáticas, siendo las primeras tareas el trazar gráficas, resolver sistemas de ecuaciones y/o derivadas e integrales, cosas de esas. Comencé en un primer intento utilizando Geogebra, un programa muy ligero, fácil de utilizar y sobre todo gratis, pero pronto dejo de ser útil para mis propósitos (en ese entonces Geogebra no tenía herramientas de CAS). En esa búsqueda me cruce con Matemáticas de Microsoft (Versión 2009), pero de la misma forma pronto dejo de ser lo suficientemente útil. Para ese entonces tenía en mi lista de seguimiento algunos de los programas más comunes: Derive, Mathematica, MATLAB, Maple e incluso Octave. Después de escuchar sugerencias e 'investigar' un poco acerca de los mismos, me decidí por comenzar a utilizar Maple, y bueno, a decir verdad quedé maravillado, todo era más simple con Maple y además ¿qué no podía resolver Maple?, lo hacía todo.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Poco después, y por obligación, llego MATLAB, era el lenguaje de programación que utilizaría en mi curso de Métodos Numéricos. Al principio me pareció poco "amigable" y más aun porque la versión que utilizaba (R2008a) no disponía de un toolbox de Matemáticas Simbólicas, así que no podía realizar operación algebraica de ningún tipo, lo cual no representaba limitación alguna para cubrir el curso que estaba llevando.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Pero bueno, en ese entonces estaba muy "verde" como para comprender la utilidad real de un programa tan potente como MATLAB. Le abandoné unos meses, hasta que por necesidad tuve que recurrir a este nuevamente para implementar algoritmos de simulaciones numéricas en un curso de Resistencia de Materiales. </div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b>DE LA PROGRAMACIÓN...</b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Como mencioné anteriormente, tuve que recurrir a MATLAB para desarrollar algoritmos, y me pareció realmente sencillo de utilizar. Llevar un pseudocódigo a MATLAB resulta muy eficaz en cuestión de tiempo de implementación, además de que la curva de aprendizaje del lenguaje es muy rápida. En cambio, utilizar Maple para implementar un algoritmo es una tarea un poco desalentadora en principio, cuesta un poco más comprender la sintaxis del lenguaje. Probablemente lo anterior se deba a que MATLAB tiene muchas similitudes con un lenguaje de programación tan popular como C, en cambio Maple tiene una sintaxis muy distinta a C y más afín a lenguajes como Modula.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b>DE LAS INTERFACES GRÁFICAS...</b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">En MATLAB se pueden desarrollar interfaces gráficas de una calidad aceptable y con una facilidad "tremenda", incluso con el entorno de desarrollo (GUIDE) la tarea se vuelve mucho más sencilla. Maple, también proporciona un entorno de desarrollo para Maplets (interfaces gráficas creadas en Maple), pero la documentación disponible es muy limitada, lo cual hace aún más complicado el desarrollo de las mismas.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b>DE LA DOCUMENTACIÓN...</b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Tanto MATLAB como Maple proporcionan una documentación muy extensa, con ejemplos para cada una de sus funciones, demos e incluso vídeo tutoriales en el sitio web oficial de cada uno. No obstante, en cuanto a información existente escrita por terceros, es innegable que MATLAB dispone de mucha más información, consecuencia directa del número de usuarios de cada uno de los programas.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b>EN RESUMEN...</b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Puede sonar demasiado obvio, pero lo cierto es que la elección dependerá del uso que se le dará al programa. Maple puede resultar muy útil para resolver todo tipo de problemas que involucren cálculo simbólico, en eso no hay discusión, además como herramienta didáctica en problemas de matemáticas resulta totalmente adecuado, debido a su fácil manejo y a la forma en que presenta sus resultados. MATLAB, por el contrario, resultará más útil para aplicaciones que requieran el manejo de técnicas numéricas, para desarrollar algoritmos y/o simulaciones e incluso para procesar datos que provienen de una aplicación externa. </div><div style="text-align: justify;"><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-89729814626276418562014-07-08T23:28:00.000-05:002016-03-21T22:38:50.728-06:00Graficando un "toro" en MATLAB<div style="text-align: justify;">Un toro es una superficie o sólido de revolución generado por la rotación de una circunferencia alrededor de un eje determinado.</div><br /><div style="text-align: justify;">Para nuestro caso utilizaremos la circunferencia de radio 1 y coordenadas de centro (1,2), cuya ecuación en coordenadas cartesianas sería:</div><br />$$(x-1)^2+(y-2)^2=1$$<br /><br /><div style="text-align: justify;">La ecuación anterior está dada de forma implícita, pero para nuestros fines necesitamos la función de la circunferencia de forma explícita, lo cual nos conduce a despejar la variable dependiente "y" y expresar la circunferencia mediante las dos funciones que se muestran enseguida:</div><br /><div class="MsoNormal">$$ \left\{ \begin{array}{cc} y_1=\sqrt{1-(x-1)^2}+2 \\ y_2=-\sqrt{1-(x-1)^2}+2 \end{array} \right. $$</div><div><br />Una vez comprendido lo anterior, podemos centrarnos en la función cylinder nativa de MATLAB que nos permite generar un sólido de revolución mediante la sintaxis:<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> cylinder(fun);</span><br /><br />Donde "fun" es una función $f(x)$ y que sirve para establecer el perfil del sólido de revolución. Regresando a nuestro objetivo principal, enseguida se muestra el código necesario para generar la gráfica de un toro, utilizando las dos funciones mencionadas con anterioridad:<br /><br /><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><div style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1pt solid windowtext; padding: 1pt 4pt;"><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';">x=0:0.1:2;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';">f1=sqrt(1-(x-1).^2)+2;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';">f2=-sqrt(1-(x-1).^2)+2;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';">hold </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">on</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';">cylinder(f1);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New';">cylinder(f2);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';">daspect([1 1 1]);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New';">view(3);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyuhjaGXCcPG2fnoOuJ1F7NPgSH0S6TY9b3u5eRRw0coFIwAza66ID1DnMrm7o5nkU1cBJQJTFkuy5A420YOrLreyg7LFmo9ZPfCTM8XxANzPl9TW3bSVWkgBkrOmaGnPzOsmcHUqyWgif/s1600/toro.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyuhjaGXCcPG2fnoOuJ1F7NPgSH0S6TY9b3u5eRRw0coFIwAza66ID1DnMrm7o5nkU1cBJQJTFkuy5A420YOrLreyg7LFmo9ZPfCTM8XxANzPl9TW3bSVWkgBkrOmaGnPzOsmcHUqyWgif/s1600/toro.PNG" height="356" width="400" /></a></div><br /><br /><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com1tag:blogger.com,1999:blog-6491678271581908753.post-66540635565427747072014-05-28T23:47:00.000-05:002016-03-21T22:38:50.682-06:00Números primos en MATLAB<div style="text-align: justify;">Un <b>número primo</b> es un entero mayor a uno que únicamente tiene dos divisores: la unidad y el número mismo. A excepción del 2, el resto de número primos son impares.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">MATLAB dispone de la función nativa <span style="font-family: Courier New, Courier, monospace;">isprime</span> para determinar si un número es primo, devolviendo un valor lógico verdadero en caso de serlo y falso en caso contrario. Por ejemplo:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><div><span style="font-family: Courier New, Courier, monospace;">>> isprime(11)</span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;">ans =</span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"> 1</span></div><div><br /></div><div>Ahora, la idea es crear por nosotros mismos un algoritmo sencillo que determine si un número es primo. Para ello optaremos por hacer lo siguiente: sea $n$ el número a verificar, entonces crearemos un vector cuyos términos sean todos los enteros positivos en el intervalo $[1,n]$, enseguida mediante una sentencia de control if verificar mediante la función <span style="font-family: Courier New, Courier, monospace;">rem</span> si cada uno de los componentes del vector es divisor de $n$, recuerde que <span style="font-family: Courier New, Courier, monospace;">rem</span> devuelve un cero si el segundo argumento es divisor del primero y un número mayor a cero si no lo es. Véase el código resultante de lo que se ha descrito:<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">n=input(</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Introduzca un número: '</span><span style="font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">L=1:n; </span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">if</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">nnz(rem(n,L)==0)==2</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="font-family: 'Courier New'; font-size: 10pt;">disp(</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Número primo'</span><span style="font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">else</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;"> disp(</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Número no primo'</span><span style="font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div></div></div><div><br /><br /></div></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-30241804472887596542014-05-27T00:43:00.000-05:002016-03-21T22:38:50.631-06:00Trazar polígonos en MATLAB<div style="text-align: justify;">La siguiente función permite trazar un polígono de N lados, siendo los argumentos de entrada el número de lados, el radio de la circunferencia en la cuál el polígono se encuentra inscrito, y las coordenadas del centro del polígono.</div><br /><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">function</span><span lang="EN-US" style="font-family: 'Courier New';"> h=poligono(N,r,cx,cy)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="color: forestgreen; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">% Traza un polígono de N lados</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">t = (1/(2*N):1/N:1)*2*pi;</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">x = r*sin(t)+cx;</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">y = r*cos(t)+cy;</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">h=fill(x,y,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'r'</span><span style="font-family: 'Courier New';">);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">axis </span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">square</span><span style="font-family: 'Courier New';">;</span></div><div class="MsoNormal" style="background: rgb(238, 236, 225); margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><br />Enseguida se muestra un ejemplo para el polígono de 6 lados (hexágono):<br /><br /><span style="font-family: Courier New, Courier, monospace;">>> poligono(6,1,0,0);</span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnfPUlDQTBJoOLTOAQQ77uXuOmclCAY-yWzdGtDbZjZp5DN8sj6zqcBKh8kX4OPRRCPbU0mn3KfONkiEIeDzGWNqAyxcjShLUBOY0PnJRSOipGQlxfWwNdGmoGRBoNqf_Da4qVmQGcqtb4/s1600/img.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnfPUlDQTBJoOLTOAQQ77uXuOmclCAY-yWzdGtDbZjZp5DN8sj6zqcBKh8kX4OPRRCPbU0mn3KfONkiEIeDzGWNqAyxcjShLUBOY0PnJRSOipGQlxfWwNdGmoGRBoNqf_Da4qVmQGcqtb4/s1600/img.png" height="300" width="400" /></a></div><br />El usuario puede además hacer adecuaciones a la visualización del polígono utilizando el handles del mismo.<br /><br /><br />Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-74453323230617826692014-05-13T23:24:00.000-05:002016-03-21T22:38:50.697-06:00Personalizar Push Button en una GUI MATLAB<div style="text-align: justify;">Cuando se crea un Push Button en una GUI MATLAB existen ciertas limitaciones para personalizar la visualización del mismo. De forma ordinaria se puede modificar el color de fondo mediante la propiedad BackgroundColor, el tamaño de fuente con FontSize, el estilo de fuente con FontWeight, el tipo de fuente con FontName, e incluso poner una imagen de fondo (<a href="http://matlab-typ.blogspot.mx/2013/11/colocar-imagenicono-de-fondo-en-un-push.html">Véase este post</a> ). No obstante utilizando las bondades del lenguaje HTML se puede disponer de mayores opciones, enseguida se tratarán algunas de las características más importantes que pueden modificarse.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span style="font-family: Verdana, sans-serif;">Colocar letras griegas </span></b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">En ingeniería es muy común el uso del alfabeto griego para representar diversas magnitudes. Para colocar letras griegas en el "String" del Push Button deben utilizarse las etiquetas HTML y anteponer un ampersand (&) al nombre de la letra griega. Por ejemplo si requiere utilizar la siguiente expresión: $Calcular\,\,\,\beta$, entonces deberá modificar el "String" como se muestra enseguida:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><div class="MsoNormal" style="background-color: #d9d9d9; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">str=</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'<html>Calcular &beta</html>'</span><span style="font-family: 'Courier New';">;</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #d9d9d9; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(hPB,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'String'</span><span style="font-family: 'Courier New';">,str);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6HvTtCdAS4t3XHgXElv92os7db2xqs5ai-yTrcQheTen2yPZ-RUOv43QO_ftY6J4k6b1KpsJMpSfYZbPTL6PLJrKa5Qv2oql3yQLgQ0GPaCDGuFRVBrIUfhD8oooSJV1Op2w_WMl8wuiB/s1600/PBletrag.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6HvTtCdAS4t3XHgXElv92os7db2xqs5ai-yTrcQheTen2yPZ-RUOv43QO_ftY6J4k6b1KpsJMpSfYZbPTL6PLJrKa5Qv2oql3yQLgQ0GPaCDGuFRVBrIUfhD8oooSJV1Op2w_WMl8wuiB/s1600/PBletrag.PNG" /></a></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">En las líneas anteriores <span style="font-family: Courier New, Courier, monospace;">hPB</span> es el handle del Push Button (en un Push Button creado con GUIDE se utilizar la referencia <span style="font-family: Courier New, Courier, monospace;">handles.tagBoton</span>).</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: Verdana, sans-serif;"><b>Subíndices y superíndices</b></span></div><div style="text-align: justify;"><br />En HTML se utilizan las etiquetas <sub></sub> para indicar un subíndice y <sup></sup> para superíndices. Claro, como en el caso anterior estas deben ir entre etiquetas HTML para que MATLAB lo reconozca como tal, véase el siguiente ejemplo en el cual se utiliza como "String" la expresión: $a^2+b^2=k_0$<br /><br /><div class="MsoNormal" style="background-color: #d9d9d9; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';">str=</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'<html>a<sup>2</sup>+b<sup>2</sup>=k<sub>0</sub></html>'</span><span lang="EN-US" style="font-family: 'Courier New';">;</span></div><div class="MsoNormal" style="background-color: #d9d9d9; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(hPB,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'String'</span><span style="font-family: 'Courier New';">,str);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3yOynGfaJim_TinltIZel5NXSGZt4xGWhWSZwCiVXR9G6cZTPhnEB2E89VK5djP_659Ycm2IkSC_NIdoCZhkyAEr1kACm3XTqsAg1dSRzatrK3FTB1AQxqoUA6cq7w78J2eH8EhZ6WXRD/s1600/PBsubsup.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3yOynGfaJim_TinltIZel5NXSGZt4xGWhWSZwCiVXR9G6cZTPhnEB2E89VK5djP_659Ycm2IkSC_NIdoCZhkyAEr1kACm3XTqsAg1dSRzatrK3FTB1AQxqoUA6cq7w78J2eH8EhZ6WXRD/s1600/PBsubsup.PNG" /></a></div><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><b><span style="font-family: Verdana, sans-serif;">Múltiples líneas</span></b><br /><br />Para colocar más de una linea en un Push Button puede utilizarse la etiqueta HTML de salto de línea <br>, véase el ejemplo a continuación:<br /><br /><div class="MsoNormal" style="background-color: #d9d9d9; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">str=</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'<html>Primera línea <br> Segunda línea</html>'</span><span style="font-family: 'Courier New';">;</span></div><div class="MsoNormal" style="background-color: #d9d9d9; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(hPB,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'String'</span><span style="font-family: 'Courier New';">,str);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW5LfPeqhuxONxDNIlYs18aQ_tbgsdSG-ZrQhEOyLLf__QLG59BoZf25KnHOnh9VBEBmHfVsvfp_51W0djd8MfTlcNFpSGb7QtRaKMagGI6y6q2l1O2KeHOv6yQ2DlvkjFp9_wgWIJPw73/s1600/PBlinmult.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW5LfPeqhuxONxDNIlYs18aQ_tbgsdSG-ZrQhEOyLLf__QLG59BoZf25KnHOnh9VBEBmHfVsvfp_51W0djd8MfTlcNFpSGb7QtRaKMagGI6y6q2l1O2KeHOv6yQ2DlvkjFp9_wgWIJPw73/s1600/PBlinmult.PNG" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: justify;">Para una referencia más completa acerca de las características HTML vistas en este post puede visitar los siguientes enlaces:</div><div class="separator" style="clear: both; text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: justify;"><a href="http://lineadecodigo.com/html/alfabeto-griego-en-html/">Letras griegas</a></div><div class="separator" style="clear: both; text-align: justify;"><a href="http://www.html.com.es/web.php?seccion=sub-super-indice">Subíndices y superíndices</a></div><div class="separator" style="clear: both; text-align: justify;"><a href="http://www.w3schools.com/tags/tag_br.asp">Saltos de línea</a></div><div class="separator" style="clear: both; text-align: justify;"><br /></div></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com2tag:blogger.com,1999:blog-6491678271581908753.post-18092416973976793972014-05-13T00:21:00.000-05:002016-03-21T22:38:50.603-06:00Gráficas de barras<div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Las gráficas de barras </span><span style="background-color: white; color: #252525; font-family: Arial, Helvetica, sans-serif; line-height: 22.399999618530273px;">es una forma de representar gráficamente un conjunto de datos o valores y está conformado por barras </span><span style="font-family: Arial, Helvetica, sans-serif;">rectangulares</span><span style="background-color: white; color: #252525; font-family: Arial, Helvetica, sans-serif; line-height: 22.399999618530273px;"> de </span><span style="font-family: Arial, Helvetica, sans-serif;">longitudes</span><span style="background-color: white; color: #252525; font-family: Arial, Helvetica, sans-serif; line-height: 22.399999618530273px;"> proporcionales a los valores representados.</span></div><div style="text-align: justify;"><span style="background-color: white; color: #252525; font-family: Arial, Helvetica, sans-serif; line-height: 22.399999618530273px;"><br /></span></div><div style="text-align: justify;"><span style="color: #252525; font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; line-height: 22.399999618530273px;">Para nuestro ejemplo utilizaremos la información proporcionada por la siguiente tabla:</span></span></div><div style="text-align: justify;"><span style="background-color: white; color: #252525; font-family: Arial, Helvetica, sans-serif; line-height: 22.399999618530273px;"><br /></span></div><div style="text-align: justify;"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"> <tbody><tr> <td style="background: #0F243E; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" width="121"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b><span style="font-family: "Tw Cen MT Condensed","sans-serif"; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: white;">ASIGNATURA</span><o:p></o:p></span></b></div></td> <td style="background: #0F243E; border-left: none; border: solid windowtext 1.0pt; mso-background-themecolor: text2; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 92.15pt;" width="123"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b><span style="font-family: "Tw Cen MT Condensed","sans-serif"; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: white;">CALIFICACIÓN</span><o:p></o:p></span></b></div></td> </tr><tr> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Álgebra<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 92.15pt;" width="123"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">9<o:p></o:p></div></td> </tr><tr> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Geometría <o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 92.15pt;" width="123"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">9.5<o:p></o:p></div></td> </tr><tr> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Cálculo<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 92.15pt;" width="123"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">10<o:p></o:p></div></td> </tr><tr> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Estática<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 92.15pt;" width="123"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">8.5<o:p></o:p></div></td> </tr><tr> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Química<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 92.15pt;" width="123"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">8<o:p></o:p></div></td> </tr></tbody></table></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">MATLAB proporciona la función </span><span style="font-family: Courier New, Courier, monospace;">bar</span><span style="font-family: Arial, Helvetica, sans-serif;"> para trazar gráficas de barras, que en su sintaxis más simple sólo necesita como argumento un vector con los datos a graficar, véase el ejemplo a continuación:</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">calificaciones=[9,9.5,10,8.5,8];</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">bar(calificaciones);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGQNSf4gUq6pTdkSPaMXo_JSi5gwDCocn440NemP2PBtWEVbWpzzARfJzBSOLeDmMKWQMggyka0AjzvCkW3_fT6blFRY1YnWpBNyCwGG6cb4fooHk00OFkEF663yeJHo8J4Jnvp8lSP1y/s1600/img.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGQNSf4gUq6pTdkSPaMXo_JSi5gwDCocn440NemP2PBtWEVbWpzzARfJzBSOLeDmMKWQMggyka0AjzvCkW3_fT6blFRY1YnWpBNyCwGG6cb4fooHk00OFkEF663yeJHo8J4Jnvp8lSP1y/s1600/img.png" height="300" width="400" /></a></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Lo anterior resulta muy sencillo, pero aún carece de información acerca de los datos que se están mostrando. Para añadir una etiqueta a cada dato o barra que se grafica modificaremos la propiedad </span><span style="font-family: Courier New, Courier, monospace;">XTickLabel</span><span style="font-family: Arial, Helvetica, sans-serif;"> del axes al cuál pertenece el diagrama de barras, en nuestro ejemplo esas etiquetas serían el nombre de cada asignatura. Definimos las etiquetas utilizando un cell array, veáse el ejemplo:</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">asignaturas={</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Álgebra'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Geometría'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Cálculo'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Estática'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Química'</span><span style="font-family: 'Courier New';">};</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">calificaciones=[9,9.5,10,8.5,8];</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">h=bar(calificaciones);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(gca,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'XTickLabel'</span><span style="font-family: 'Courier New';">,asignaturas);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ5h-s9Q8RLUBeZfGjudXmGu9qlEv9qcBzklG3VDa5qElcSJEVaR2c45uLun9A0qsInTSFHRbE9MjdznFkd_l8M0zXZL0R3-XuExR2mDgetjhWZBkNHlEDI1S3WoJcs4SeGlD_LP7C1vMe/s1600/img.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ5h-s9Q8RLUBeZfGjudXmGu9qlEv9qcBzklG3VDa5qElcSJEVaR2c45uLun9A0qsInTSFHRbE9MjdznFkd_l8M0zXZL0R3-XuExR2mDgetjhWZBkNHlEDI1S3WoJcs4SeGlD_LP7C1vMe/s1600/img.png" height="300" width="400" /></a></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="color: #073763; font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Modificar el ancho y color de las barras.</b></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Para modificar el ancho de las barras basta con pasar como segundo argumento de la función bar un valor escalar entre 0 y 1, la sintaxis sería:</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">bar(X,k);</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Donde X es el vector que contiene los valores y k un escalar en el intervalo 0 a 1.</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Por defecto MATLAB utiliza el color azul para las gráficas de barras, pero existe la posibilidad de cambiar el color a conveniencia del usuario. Para ello puede especificarse el color como un segundo argumento de la función bar, mediante un especificador de color (</span><span style="font-family: Courier New, Courier, monospace;">'r','g','b','k',...</span><span style="font-family: Arial, Helvetica, sans-serif;">), con la sintaxis:</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">bar(X,'color');</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Donde X es el vector de valor y '</span><span style="font-family: Arial, Helvetica, sans-serif;">color</span><span style="font-family: Arial, Helvetica, sans-serif;">' el especificador de color mediante caracteres.</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">Si requiere modificar el grosor y color a la vez, puede usar la siguiente sintaxis:</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Courier New, Courier, monospace;">bar(X,k,'color');</span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">El siguiente ejemplo muestra una gráfica de barras con el ancho y color modificados:</span><br /><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br /><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">asignaturas={</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Álgebra'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Geometría'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Cálculo'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Estática'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Química'</span><span style="font-family: 'Courier New';">};</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">calificaciones=[9,9.5,10,8.5,8];</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">bar(calificaciones,0.4,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'r'</span><span style="font-family: 'Courier New';">);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(gca,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'XTickLabel'</span><span style="font-family: 'Courier New';">,asignaturas);</span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">title(</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Calificaciones'</span><span style="font-family: 'Courier New';">);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrCKpwxTvEWb_7RUfl2ttqcav0JZ_rxSMzRjRqGwmK7fDLaajdJYqW2ZlzIqnV7k0EDQfX9L0JkNiT9JuMNu53LseO3PameIqIagZ8NblL1w59HmHHAG6OyTu3rYX3Rk33gV19ww8TW4_W/s1600/img.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrCKpwxTvEWb_7RUfl2ttqcav0JZ_rxSMzRjRqGwmK7fDLaajdJYqW2ZlzIqnV7k0EDQfX9L0JkNiT9JuMNu53LseO3PameIqIagZ8NblL1w59HmHHAG6OyTu3rYX3Rk33gV19ww8TW4_W/s1600/img.png" height="300" width="400" /></a></div><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><span style="color: #073763; font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Gráficas de barras múltiples.</b></span><br /><br /><span style="font-family: Arial, Helvetica, sans-serif;">En ocasiones se necesita representar más de un valor asociado a una misma característica, para ello es posible graficar diagramas de barras utilizando matrices en lugar de un vector, en donde cada fila proporciona los valores de una misma característica y cada columna pertenece a una categoría distinta entre los valores. Para nuestro ejemplo utilizaremos la tabla mostrada enseguida.</span><br /><br /></div><div style="text-align: justify;"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;"> <tbody><tr style="height: 14.0pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"> <td rowspan="2" style="background: #002060; border: solid windowtext 1.0pt; height: 14.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" width="121"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b><span style="color: white;">ALUMNO</span><o:p></o:p></b></div></td> <td colspan="3" style="background: #002060; border-left: none; border: solid windowtext 1.0pt; height: 14.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 233.9pt;" width="312"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><b><span style="color: white;">CALIFICACIONES</span><o:p></o:p></b></div></td> </tr><tr style="height: 7.45pt; mso-yfti-irow: 1;"> <td style="background: #244061; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 7.45pt; mso-background-themecolor: accent1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><span style="color: white;">MATEMÁTICAS<o:p></o:p></span></div></td> <td style="background: #244061; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 7.45pt; mso-background-themecolor: accent1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 63.8pt;" width="85"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><span style="color: white;">FÍSICA<o:p></o:p></span></div></td> <td style="background: #244061; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 7.45pt; mso-background-themecolor: accent1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;"><span style="color: white;">QUÍMICA</span><o:p></o:p></div></td> </tr><tr style="height: 14.0pt; mso-yfti-irow: 2;"> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Ana<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">10<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 63.8pt;" width="85"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">7<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">9<o:p></o:p></div></td> </tr><tr style="height: 13.2pt; mso-yfti-irow: 3;"> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; height: 13.2pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Jorge<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.2pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">8<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.2pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 63.8pt;" width="85"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">8<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.2pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">10<o:p></o:p></div></td> </tr><tr style="height: 14.0pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes;"> <td style="background: #D9D9D9; border-top: none; border: solid windowtext 1.0pt; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 90.45pt;" valign="top" width="121"><div class="MsoNormal" style="margin-bottom: 0.0001pt;">Javier<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">9<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 63.8pt;" width="85"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">9<o:p></o:p></div></td> <td style="background: #D9D9D9; border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 3.0cm;" width="113"><div align="center" class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center;">8<o:p></o:p></div></td> </tr></tbody></table></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;">En la tabla anterior cada alumno tiene tres calificaciones asociadas en diferentes asignaturas. El siguiente ejemplo muestra cómo trazar la gráfica de barras correspondiente:</span><br /><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br /><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">nombres={</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Ana'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Jorge'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'Javier'</span><span style="font-family: 'Courier New';">};</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">Ana=[10,7,9];</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">Jorge=[8,8,10];</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">Javier=[9,9,8];</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">bar([Ana;Jorge;Javier]);</span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(gca,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'XtickLabel'</span><span style="font-family: 'Courier New';">,nombres);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div><div style="text-align: justify;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj131OSd2DoVS2KzFvwgtDKobihRGP_MfCpJ_wKmmH0ndivhlnk0n5pwVfTStFZI07SSD4IkG26FoZrn1b3XX5oT4zp-lTKAwvRCXwPszs5bIQU8D697EETBScHVIuUMGV-cbvw7rhDbk9h/s1600/img.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj131OSd2DoVS2KzFvwgtDKobihRGP_MfCpJ_wKmmH0ndivhlnk0n5pwVfTStFZI07SSD4IkG26FoZrn1b3XX5oT4zp-lTKAwvRCXwPszs5bIQU8D697EETBScHVIuUMGV-cbvw7rhDbk9h/s1600/img.png" height="300" width="400" /></a></div></div><div style="text-align: justify;"><span style="background-color: white; color: #252525; font-family: Arial, Helvetica, sans-serif; line-height: 22.399999618530273px;"><br /></span></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com5tag:blogger.com,1999:blog-6491678271581908753.post-72516453352747274352014-05-12T12:40:00.000-05:002016-03-21T22:38:50.692-06:00Visualizador de imágenes<div>La siguiente GUI hace la función de un visualizador de imágenes, seleccionando una carpeta en la cual estén situadas las imagenes.</div><div><br /></div><div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> verImg</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">clearvars(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'-global'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">figure(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'MenuBar'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'none'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'NumberTitle'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'off'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Name'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Visualizador de imágenes'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">...</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Resize'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'off'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">...</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Position'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,[200 200 450 350]);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New'; font-size: 10pt;">centerfig;</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New'; font-size: 10pt;">uimenu(</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Label'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Seleccionar carpeta'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Callback'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,@selFcn);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">ax=axes(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'units'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'pixels'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Position'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,[25 25 400 300],</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'Visible'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'off'</span><span style="font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">uicontrol(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'style'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'push'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'String'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'<<'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Position'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,[0 165 20 20],</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Callback'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,@cambiar);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">uicontrol(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'style'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'push'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'String'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'>>'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Position'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,[430 165 20 20],</span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">...</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Callback'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,@cambiar);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> selFcn(src,~)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">global</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> carp Imgs cont</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> cont=1;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> carp=uigetdir;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">if</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> isequal(carp,0)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">return</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">end</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> Imgs=dir([carp,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'/*.jpg'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">]);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> imshow(imread([carp,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'/'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,Imgs(cont).name]));</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">end</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><br /></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">function</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> cambiar(src,~)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">global</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> carp cont Imgs</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">if</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> (strcmp(get(src,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'str'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">),</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'>>'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">) && cont<length(Imgs))</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> cont=cont+1;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> imshow(imread([carp,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'/'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,Imgs(cont).name]));</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">elseif</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> (strcmp(get(src,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'str'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">),</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'<<'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">) && cont>1)</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> cont=cont-1;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> imshow(imread([carp,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'/'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,Imgs(cont).name]));</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div></div><div><br /></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEpNA1o_mR4GGwzmfzuz3R8JODgo-gCPM1GvE3UTymnxdOVNZRwPQq9xxDCtujEMacdxOyfGDhkb87iEeMo0RPNUGoQiQoojFRg7vSpbml1hZNj1tZJhiTIT2uJlP69_zgwMxFxyLsWRe/s1600/VisImag.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEpNA1o_mR4GGwzmfzuz3R8JODgo-gCPM1GvE3UTymnxdOVNZRwPQq9xxDCtujEMacdxOyfGDhkb87iEeMo0RPNUGoQiQoojFRg7vSpbml1hZNj1tZJhiTIT2uJlP69_zgwMxFxyLsWRe/s1600/VisImag.PNG" height="285" width="320" /></a></div><div><br /></div><div><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com2tag:blogger.com,1999:blog-6491678271581908753.post-76911687703168493372014-05-12T08:36:00.000-05:002016-03-21T22:38:50.705-06:00Sucesión de Fibonacci en MATLAB<div style="text-align: justify;">La sucesión de Fibonacci es una sucesión infinita de números naturales, cuyos términos resultan de la suma de los dos términos anteriores. Los primeros dos términos son 1 y 1, y enseguida el resto siguen el patrón descrito con anterioridad, así, algunos de los primeros términos se muestran enseguida:</div><br />$$1,1,2,3,5,8,13,21,34,55,...$$<br /><br /><div style="text-align: justify;">Luego, cada término de la sucesión se calcula bajo la siguiente especificación: $f_i=f_{i-1}+f_{i-2}$. La implementación en MATLAB resulta muy sencilla, primero definiéndose los dos primeros términos y enseguida concatenar los que siguen el patrón mencionado mediante un bucle. Un código de ejemplo se muestra a continuación:</div><br /><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">n=input(</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'¿Cuántos términos necesita? '</span><span style="font-family: 'Courier New';">);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">F=[1 1]; </span><span style="color: forestgreen; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">% Primeros dos términos de la sucesión</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">for</span><span lang="EN-US" style="font-family: 'Courier New';"> i=3:n</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';"> F=[F F(i-1)+F(i-2)];</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">end</span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">disp(F);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><br /><br /><br /><br /><br /><br /><br />Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-21970973803903076132014-05-07T03:12:00.000-05:002016-03-21T22:38:50.608-06:00Personalizar un msgbox<div style="text-align: justify;">Para comenzar, un msgbox es un elemento gráfico utilizado para enviar mensajes al usuario, por ejemplo una sugerencia, un mensaje de advertencia o error. La sintaxis más simple para crear un msgbox es la siguiente:</div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;">msgbox('Mensaje','Título de la ventana');</span></div><div><br /></div><div style="text-align: justify;">Con la sintaxis anterior se muestra un msgbox con características ordinarias y establecidas por defecto, como el que se muestra enseguida:</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOXGDag_xhWfpuJd8ZAu9WedgW2zwFuQvHTqPDoLSMM0o1O2NGzdrlqxcGxjJx55h6-PO0r0dhcajxoeDixEHDBePodYqf7rhViyfM86T-NVo0aXJUkxlckYGGagMMLX8cgXI_O85jSGRT/s1600/msgbox1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOXGDag_xhWfpuJd8ZAu9WedgW2zwFuQvHTqPDoLSMM0o1O2NGzdrlqxcGxjJx55h6-PO0r0dhcajxoeDixEHDBePodYqf7rhViyfM86T-NVo0aXJUkxlckYGGagMMLX8cgXI_O85jSGRT/s1600/msgbox1.PNG" /></a></div><div><br /></div><div><br /></div><div style="text-align: justify;">La función msgbox no cuenta con argumentos de entrada que sirvan para especificar una apariencia diferente del cuadro de diálogo mostrado. Pero existe la posibilidad de personalizar un msgbox accediendo mediante referencias (handles) a sus componentes gráficos elementales.</div><div style="text-align: justify;"><br /></div><div><b>Modificando el color de la ventana</b></div><div><br /></div><div style="text-align: justify;">Es evidente que la ventana gráfica de un msgbox es un elemento figure y por tanto pueden modificarse sus propiedades como tal; para ello debe utilizarse el handle del msgbox como argumento de la función set, véase el ejemplo mostrado enseguida:</div><div><br /></div><div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';">h=msgbox(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'MATLAB TYP'</span><span lang="EN-US" style="font-family: 'Courier New';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'V1'</span><span lang="EN-US" style="font-family: 'Courier New';">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">set(h,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'color'</span><span style="font-family: 'Courier New';">,</span><span style="color: #a020f0; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">'g'</span><span style="font-family: 'Courier New';">); </span><span style="color: forestgreen; font-family: "Courier New"; mso-bidi-font-size: 10.0pt;">% Establece color verde para la ventana</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWwPyRYYHQqxN1VDgOSkfvtKpKB9pmzl1_PSJA1DpFuza_-_bOYkFlGckO2_91swXh_JMeuNTDBD7UK-XbDY9AxDuNlKXTkrwkoDks3FTXuGwG0uJ_00VOgJfJ8c2DqSa2elhxhi0JiC5Y/s1600/msgbox2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWwPyRYYHQqxN1VDgOSkfvtKpKB9pmzl1_PSJA1DpFuza_-_bOYkFlGckO2_91swXh_JMeuNTDBD7UK-XbDY9AxDuNlKXTkrwkoDks3FTXuGwG0uJ_00VOgJfJ8c2DqSa2elhxhi0JiC5Y/s1600/msgbox2.PNG" /></a></div><div><br /></div><div><br /></div><div><b>Modificando el tamaño, estilo y tipo de fuente.</b></div><div><br /></div><div style="text-align: justify;">Para configurar las propiedades del mensaje que se muestra debemos acceder a la referencia del edit text que lo contiene; utilizando la función <span style="font-family: Courier New, Courier, monospace;">allchild</span> se obtienen todos los elementos gráficos "hijos" del objeto pasado como argumento, por ejemplo para el msgbox en cuestión:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';">h=msgbox(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'MATLAB TYP'</span><span lang="EN-US" style="font-family: 'Courier New';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'V1'</span><span lang="EN-US" style="font-family: 'Courier New';">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span style="font-family: 'Courier New';">ch = allchild(h);</span><span style="font-family: "Courier New"; font-size: 14.0pt; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div><br /></div><div>La función <span style="font-family: Courier New, Courier, monospace;">allchild</span> nos devuelve simplemente las referencias o handles de los objetos pero no indica el tipo de los mismos, para identificar el tipo de objeto gráfico puede utilizarse la función <span style="font-family: Courier New, Courier, monospace;">get</span> como sigue:</div><div><br /></div><div><div><span style="font-family: Courier New, Courier, monospace;">>> get(ch,'type')</span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;">ans = </span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"> 'axes'</span></div><div><span style="font-family: Courier New, Courier, monospace;"> 'uicontrol'</span></div></div><div><br /></div><div style="text-align: justify;">El objeto <span style="font-family: Courier New, Courier, monospace;">uicontrol</span> es el botón mostrado en el msgbox, y el axes es el elemento que contiene al edit text que nos interesa; para obtener el handle del edit text podemos utilizar la función <span style="font-family: Courier New, Courier, monospace;">get</span> como se muestra enseguida:</div><div><br /></div><div><span style="font-family: 'Courier New', Courier, monospace;">txt=get(ch(1),'children')</span></div><div><br /></div><div style="text-align: justify;">Con la linea anterior se obtiene y guarda en la variable txt el handle del objeto "hijo" del axes, que en este caso es el edit text. Ahora, una vez que se dispone de la referencia, pueden modificarse las propiedades del edit text de forma ordinaria con la función set, en nuestro caso modificaremos específicamente la propiedad tamaño (<span style="font-family: Courier New, Courier, monospace;">FontSize</span>), estilo (<span style="font-family: Courier New, Courier, monospace;">FontWeight</span>) y tipo (<span style="font-family: Courier New, Courier, monospace;">FontName</span>), véase el ejemplo siguiente:</div><div><br /></div><div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">h=msgbox(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'MATLAB TYP'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'V1'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">ch = allchild(h);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">txt = get(ch(1),</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'children'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">set(txt,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'FontSize'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,12,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'FontName'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'Berlin Sans FB'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'FontWeight'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'bold'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div></div><div><br /></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRRS1xy9F5HVj5J62d3BUfEr8RqWVp4hafVqAAswUYoUqs1c3HfZMgo6QBhnincqSw9TmnOjitP8SMJV7O6Ee33-hbNWmWk38DO4YI03CFPVt95OzOAKM6C4E9evYTKRxiMPvWev8WRSrR/s1600/msgbox3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRRS1xy9F5HVj5J62d3BUfEr8RqWVp4hafVqAAswUYoUqs1c3HfZMgo6QBhnincqSw9TmnOjitP8SMJV7O6Ee33-hbNWmWk38DO4YI03CFPVt95OzOAKM6C4E9evYTKRxiMPvWev8WRSrR/s1600/msgbox3.PNG" /></a></div><div><br /></div><div><br /></div><div><b>Modificando el texto mostrado en el botón</b></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">El botón de un msgbox muestra por defecto un "OK", pero claro, es posible modificarlo y adaptarlo a las necesidades del usuario. Se mencionó con anterioridad que una de las referencia obtenidas y guardadas en la variable ch pertenecía al botón, entonces, para modificar el mensaje utilizamos esa referencia en la función set y configuramos la propiedad<span style="font-family: Courier New, Courier, monospace;"> String</span> como se muestra a continuación:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';">h=msgbox(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'MATLAB TYP'</span><span lang="EN-US" style="font-family: 'Courier New';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'V1'</span><span lang="EN-US" style="font-family: 'Courier New';">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';">ch = allchild(h);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-color: #eeece1; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;"><span lang="EN-US" style="font-family: 'Courier New';">set(ch(2),</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'String'</span><span lang="EN-US" style="font-family: 'Courier New';">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt;">'Cerrar'</span><span lang="EN-US" style="font-family: 'Courier New';">);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 14.0pt; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt;"><o:p></o:p></span></div></div><div style="text-align: justify;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizfkfl4B2tOK7MKGVor-b7wa8Sf0OUz9MBSu0oU19vuihkoD2ahJy6ahg5Wy0cKbUWlIV3nhheCRByn9P0UNDNdSrCReaUAD-v2uyhy_E5Z097FylQ5x5VLvINz1fTHbyqud-wcwrkdHwH/s1600/msgbox4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizfkfl4B2tOK7MKGVor-b7wa8Sf0OUz9MBSu0oU19vuihkoD2ahJy6ahg5Wy0cKbUWlIV3nhheCRByn9P0UNDNdSrCReaUAD-v2uyhy_E5Z097FylQ5x5VLvINz1fTHbyqud-wcwrkdHwH/s1600/msgbox4.PNG" /></a></div><div style="text-align: justify;"><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com1tag:blogger.com,1999:blog-6491678271581908753.post-87914139115261930792014-03-28T20:11:00.000-06:002016-03-21T22:38:50.723-06:00Gráficas en tres dimensiones en MATLAB (Superficies, Curvas en el espacio, Planos)<span style="color: blue; font-size: x-large;"><b>Superficies</b></span><br /><div><br /></div><div><span style="color: orange; font-size: large;">Utilizando matrices</span></div><div><br /></div><div style="text-align: justify;">Una manera de graficar superficies es utilizar matrices y representarlas mediante funciones disponibles en MATLAB. Para ello debe definirse previamente una malla bidimensional utilizando el comando <span style="font-family: Courier New, Courier, monospace;">meshgrid</span>, cuyos argumentos son los intervalos de las variables independientes, por ejemplo suponga que quiere graficarse la siguiente función:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">$$f(x,y)=x^2+y^2$$<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">[X,Y]=meshgrid(-5:0.1:5);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">Z=X.^2+Y.^2;</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">surf(X,Y,Z);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJCacyiyQIxo22qugDFKA1u08Z0Ej2eh1hehIQPuD9m3h3-MHbla6yXbWTZzf4lNQ5oazLtvRS8V0QUabiXp5n83idS0G7ucBCfzKG5bNTHNfWDrsxb0RA3SMI8aD-4knphmS1oQ9QVtvs/s1600/graf1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJCacyiyQIxo22qugDFKA1u08Z0Ej2eh1hehIQPuD9m3h3-MHbla6yXbWTZzf4lNQ5oazLtvRS8V0QUabiXp5n83idS0G7ucBCfzKG5bNTHNfWDrsxb0RA3SMI8aD-4knphmS1oQ9QVtvs/s1600/graf1.png" height="240" width="320" /></a></div><br /><span style="color: orange; font-size: large;">De forma simbólica</span><br /><br />Otra forma de obtener el mismo resultado que el caso anterior, es proceder de manera simbólica. Una de las funciones que permite esto es <span style="font-family: Courier New, Courier, monospace;">ezsurf</span>, cuya forma es la siguiente:<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">ezsurf(</span><span style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt;">'x^2+y^2'</span><span style="font-family: 'Courier New'; font-size: 10pt;">,[-5 5]);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0nm8N4AcSZse3asUUZrJpEtYXo-LS8qqcn-m6Nq9ejMN-eo1RMbOK_LewJefiepRZycMl01XB0av8QrtbOhqHuiUTaFkyH1oCQZ_J7ooawVOQqRHrJywx-yfNTemeuyBrJPiLFIUGUEKE/s1600/graf2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0nm8N4AcSZse3asUUZrJpEtYXo-LS8qqcn-m6Nq9ejMN-eo1RMbOK_LewJefiepRZycMl01XB0av8QrtbOhqHuiUTaFkyH1oCQZ_J7ooawVOQqRHrJywx-yfNTemeuyBrJPiLFIUGUEKE/s1600/graf2.png" height="240" width="320" /></a></div><br />Como puede observarse, se necesitan menos líneas de código bajo este método.<br /><br /><br /><b><span style="color: blue; font-size: x-large;">Curvas en el espacio</span></b><br /><br />Para graficar curvas en el espacio se dispone del comando<span style="font-family: Courier New, Courier, monospace;"> plot3</span><span style="font-family: Arial, Helvetica, sans-serif;">,</span> cuyos argumentos son las ecuaciones paramétricas de la curva, tómese como ejemplo la siguiente curva (helice circular):<br /><br />$$ x(t)=cos(t) \,\,\,\,\,\,\,\,\, y(t)=sin(t) \,\,\,\,\,\,\,\,\, z(t)=t $$<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">t=linspace(0,10*pi,200);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">x=cos(t);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">y=sin(t);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">z=t;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">plot3(x,y,z,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'linewidth'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,2);</span></div></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9UzItUmIZIO9KW_Ve_-A2Fc3dX-bjU6ADDjsz5yZb6ZDXqjCSM9SRRdax7GBqou1kOS6D5ajVi2Onrq1D4T2U80y3zs_cVDk1WkVFxSVnTPZqyCg-OG-CJH2Iboq7LKSrDnJpzCPpK0f9/s1600/graf3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9UzItUmIZIO9KW_Ve_-A2Fc3dX-bjU6ADDjsz5yZb6ZDXqjCSM9SRRdax7GBqou1kOS6D5ajVi2Onrq1D4T2U80y3zs_cVDk1WkVFxSVnTPZqyCg-OG-CJH2Iboq7LKSrDnJpzCPpK0f9/s1600/graf3.png" height="300" width="400" /></a></div><br />Puede utilizar la forma simbólica para obtener un resultado similar al anterior con el comando <span style="font-family: Courier New, Courier, monospace;">ezplot3</span>, tal como sigue:<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">ezplot3(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'cos(t)'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'sin(t)'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'t'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,[0 10*pi]);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div></div><br /><br /><span style="color: blue; font-size: x-large;"><b>Planos</b></span><br /><br />El siguiente ejemplo muestra como graficar un plano $z=constante$, para ello se utiliza el comando fill3.<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">hold </span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">on</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">ezsurf(</span><span lang="EN-US" style="color: #a020f0; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">'x^2+y^2'</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">,[-5 5]);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">k=20;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">A=[-5 -5 k];</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">B=[-5 5 k];</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">C=[5 5 k];</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">D=[5 -5 k];</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">X=[A(1) B(1) C(1) D(1)];</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">Y=[A(2) B(2) C(2) D(2)];</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;">Z=[A(3) B(3) C(3) D(3)];</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">fill3(X,Y,Z,[0.7 0.7 0.7]);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">view(3);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkHQjwZvQXSNeLsNJKJYLA_gYHcBlGuGkbXWmSqDSVsyy-usnafgc5UoMHmtTDXKVzDQZOTufUjWdPvG4Fv0r1co17CiWN6pADxO70SHs9PYuev4lidkicRMrfe5TuaQ-J8EKFG0og9Taw/s1600/graf4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkHQjwZvQXSNeLsNJKJYLA_gYHcBlGuGkbXWmSqDSVsyy-usnafgc5UoMHmtTDXKVzDQZOTufUjWdPvG4Fv0r1co17CiWN6pADxO70SHs9PYuev4lidkicRMrfe5TuaQ-J8EKFG0og9Taw/s1600/graf4.png" height="240" width="320" /></a></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></div><div><div><br /></div></div>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0tag:blogger.com,1999:blog-6491678271581908753.post-77222103726872192892014-03-27T15:40:00.000-06:002016-03-21T22:38:50.708-06:00Animación simple MATLABCódigo de la animación<br /><br /><div style="background: #F2F2F2; border: solid windowtext 1.0pt; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;"> <div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;">x=0:0.1:10;</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-ansi-language: EN-US;">for</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> k=1:0.05:10</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> axis([0 10 -2 2]);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> y=cos(k*x);</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 12.0pt; mso-ansi-language: EN-US;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="font-family: 'Courier New'; font-size: 10pt;">plot(x,y);</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="font-family: 'Courier New'; font-size: 10pt;"> drawnow;</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="background-position: initial initial; background-repeat: initial initial; border: none; margin-bottom: 0.0001pt; padding: 0cm;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">end</span><span style="font-family: "Courier New"; font-size: 12.0pt;"><o:p></o:p></span></div></div><br /><br /><iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/ki9QpmDr-pA" width="420"></iframe>Jorgehttp://www.blogger.com/profile/07541147036056255284noreply@blogger.com0