Cajas de Herramientas
## Objetivos de Aprendizaje
- Comprender el ecosistema de cajas de herramientas de MATLAB
- Usar funciones especializadas comunes
- Identificar cuando usar cajas de herramientas especificas
## Signal Processing Toolbox
### Creacion de Senales
```matlab
% Senales basicas
t = 0:0.01:1;
sine = sin(2*pi*5*t); % Senal sinusoidal 5 Hz
cosine = cos(2*pi*5*t); % Senal cosinusoidal 5 Hz
% Onda cuadrada
sq = square(2*pi*5*t);
% Onda diente de sierra
saw = sawtooth(2*pi*5*t);
% Tren de pulsos
pulse = pulstran(t, 0:0.2:1, @rectpuls, 0.05);
```
### Filtrado
```matlab
% Disenar filtro
fs = 1000; % Frecuencia de muestreo
fc = 100; % Frecuencia de corte
[b, a] = butter(6, fc/(fs/2)); % Butterworth de 6to orden
% Aplicar filtro
filtered = filter(b, a, signal);
% Metodos de diseno de filtros
[b, a] = cheby1(4, 3, fc/(fs/2)); % Chebyshev Tipo I
[b, a] = ellip(4, 3, 40, fc/(fs/2)); % Eliptico
```
### FFT y Analisis Espectral
```matlab
% Transformada Rapida de Fourier
signal = sin(2*pi*50*t) + 0.5*sin(2*pi*120*t);
N = length(signal);
Y = fft(signal);
P = abs(Y/N);
% Eje de frecuencia
f = (0:N-1)*(fs/N);
% Graficar espectro unilateral
plot(f(1:N/2), P(1:N/2))
```
## Image Processing Toolbox
### Lectura y Visualizacion de Imagenes
```matlab
% Leer imagen
img = imread('image.png');
% Mostrar
imshow(img)
% Info de imagen
info = imfinfo('image.png');
```
### Tipos de Imagenes
```matlab
% RGB a escala de grises
gray = rgb2gray(img);
% Escala de grises a binaria
bw = imbinarize(gray);
% Espacios de color
hsv = rgb2hsv(img);
lab = rgb2lab(img);
```
### Operaciones de Imagen
```matlab
% Redimensionar
resized = imresize(img, 0.5);
% Rotar
rotated = imrotate(img, 45);
% Recortar
cropped = imcrop(img, [x, y, width, height]);
% Ecualizacion de histograma
eq = histeq(gray);
```
### Operaciones Morfologicas
```matlab
% Operaciones binarias
SE = strel('disk', 5);
dilated = imdilate(bw, SE);
eroded = imerode(bw, SE);
opened = imopen(bw, SE);
closed = imclose(bw, SE);
% Deteccion de bordes
edges = edge(gray, 'Canny');
```
## Optimization Toolbox
### Optimizacion Basica
```matlab
% Encontrar minimo de funcion de una variable
f = @(x) x^2 - 3*x + 1;
[xMin, fVal] = fminbnd(f, -10, 10);
% Encontrar minimo de funcion multivariable
f = @(x) (x(1)-2)^2 + (x(2)+1)^2;
[xMin, fVal] = fminsearch(f, [0, 0]);
```
### Optimizacion con Restricciones
```matlab
% Con restricciones
f = @(x) x(1)^2 + x(2)^2;
A = [1, 2; 3, 2];
b = [6; 5];
x0 = [1; 1];
[x, fval] = fmincon(f, x0, A, b);
% Limites
lb = [0; 0];
ub = [5; 5];
[x, fval] = fmincon(f, x0, A, b, [], [], lb, ub);
```
### Programacion Lineal y Cuadratica
```matlab
% Programacion lineal
f = [-1, -2];
A = [1, 2; 2, 1; -1, -2];
b = [6; 5; -3];
x = linprog(f, A, b);
% Programacion cuadratica
H = [2, 0; 0, 2];
f = [-2; -4];
x = quadprog(H, f);
```
## Statistics and Machine Learning Toolbox
### Fundamentos de Machine Learning
```matlab
% Entrenar clasificador simple
X = randn(100, 2);
y = X(:, 1) + X(:, 2) > 0;
% Ajustar modelo
mdl = fitcsvm(X, y);
% Predecir
[label, score] = predict(mdl, X);
```
### Agrupamiento
```matlab
% K-means clustering
data = randn(100, 2) + [randn(50, 2); randn(50, 2) + 5];
[idx, C] = kmeans(data, 2);
% Agrupamiento jerarquico
Z = linkage(data, 'ward');
dendrogram(Z);
```
### Classification Learner
```matlab
% Exportar modelo desde Classification Learner app
% Cargar modelo entrenado
load trainedModel.mat
predictions = predict(trainedModel, newData);
```
## Curve Fitting Toolbox
### Ajuste Basico
```matlab
x = 0:0.1:10;
y = 2*exp(-0.3*x) + 0.5*sin(x) + randn(1, 101)*0.1;
% Ajustar exponencial
f = fit(x', y', 'exp1');
% Ajustar polinomio
f = fit(x', y', 'poly2');
% Ecuacion personalizada
f = fit(x', y', 'a*exp(-b*x)+c');
```
## Control System Toolbox
### Funciones de Transferencia
```matlab
% Crear funcion de transferencia
num = [1, 2];
den = [1, 3, 2];
sys = tf(num, den);
% Diagrama de Bode
bode(sys)
% Respuesta al escalon
step(sys)
% Controlador PID
Kp = 1; Ki = 0.5; Kd = 0.1;
pid = pid(Kp, Ki, Kd);
```
## Symbolic Math Toolbox
### Variables Simbolicas
```matlab
% Crear variables simbolicas
syms x y z
% Expresion
f = x^2 + 2*x + 1;
g = (x + 1)^2;
% Simplificar
simplify(f - g) % 0
% Expandir y factorizar
expand(f) % x^2 + 2*x + 1
factor(x^2 - 1) % (x-1)(x+1)
```
### Calculo
```matlab
syms x
% Diferenciacion
f = x^3 + 2*x^2;
df = diff(f, x); % 3*x^2 + 4*x
% Integracion
int(f, x) % x^4/4 + 2*x^3/3
% Limites
limit(sin(x)/x, x, 0) % 1
```
### Resolviendo Ecuaciones
```matlab
syms x y
% Resolver ecuacion
solve(x^2 - 4 == 0, x) % [-2, 2]
% Resolver sistema
eqns = [x + y == 3, x - y == 1];
S = solve(eqns, [x, y]);
S.x % 2
S.y % 1
```
## Parallel Computing Toolbox
### Bucles Paralelos
```matlab
% Bucle for paralelo
parfor i = 1:1000
result(i) = heavyComputation(i);
end
% Verificar pool paralelo
parpool
```
### Computacion GPU
```matlab
% Mover arreglo a GPU
gdata = gpuArray(data);
% Operaciones con arreglos GPU
gresult = sqrt(gdata);
% Obtener resultado
result = gather(gresult);
```
## Data Science Toolbox
### Manipulacion de Datos
```matlab
% Detectar valores faltantes
ismissing(data)
% Eliminar faltantes
clean = rmmissing(data);
% Llenar faltantes
filled = fillmissing(data, 'linear');
% Promedio movil
movmean(data, 5)
```
## Mapping Toolbox
```matlab
% Crear datos geograficos
lat = [40.7, 40.8, 40.9];
lon = [-74.0, -73.9, -73.8];
geoplot(lat, lon, 'o-')
% Agregar mapa base
geobasemap streets
```
## Lista de Verificacion para Tareas Comunes
| Tarea | Caja de Herramientas |
|-------|----------------------|
| Filtrado de senales | Signal Processing |
| Procesamiento de imagenes | Image Processing |
| Optimizacion | Optimization |
| Machine learning | Statistics and Machine Learning |
| Matematicas simbolicas | Symbolic Math |
| Sistemas de control | Control System |
| Computacion paralela | Parallel Computing |
| Ajuste de curvas | Curve Fitting |
## Resumen
- Las cajas de herramientas de MATLAB extienden la funcionalidad base
- Signal Processing: filtros, FFT, analisis espectral
- Image Processing: filtros, morfologia, transformaciones
- Optimization: optimizacion lineal/no lineal
- Symbolic Math: calculos analiticos
- Parallel Computing: acelerar con multiples nucleos/GPUs
- Usar `ver` para verificar cajas de herramientas instaladas
Comments
Comments powered by Giscus
To enable comments, add your Giscus embed code here.
Learn more about Giscus →