Matlab - 3 "for" anidados + 2 "if"

 
Vista:

3 "for" anidados + 2 "if"

Publicado por Diego (1 intervención) el 28/11/2009 19:36:52
Buen día,
necesito hacer un ejemplo (el que sea) en Matlab que incluya 3 for anidados y 2 if... tendrán algun ejemplo que me puedan compartir? Gracias.

Saludos,
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:3

Publicado por Manu (15 intervenciones) el 01/12/2009 23:54:32
te vale algo asi?

cont = 0;

for i=1:10
for j= 3:45
for k = 2:4:18

if((i + j) > 6)
if(k < 12)
cont = cont + 1;
end
end

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

RE:3

Publicado por fismat (391 intervenciones) el 05/12/2009 17:04:31
Hola Diego,

Aca un ejemplo para invertir matrices.

Espero que sea de ayuda.

Fismat
[email protected]
............

function b = mat_inv2(a)
% Find dimensions of input matrix
[r,c] = size(a);

% If input matrix is not square, stop function
if r ~= c
disp('Only Square Matrices, please')
b = [];
return
end

% Target identity matrix to be transformed into the output
% inverse matrix
b = eye(r);

%The following code actually performs the matrix inversion
for j = 1 : r
for i = j : r
if a(i,j) ~= 0
for k = 1 : r
s = a(j,k); a(j,k) = a(i,k); a(i,k) = s;
s = b(j,k); b(j,k) = b(i,k); b(i,k) = s;
end
t = 1/a(j,j);
for k = 1 : r
a(j,k) = t * a(j,k);
b(j,k) = t * b(j,k);
end
for L = 1 : r
if L ~= j
t = -a(L,j);
for k = 1 : r
a(L,k) = a(L,k) + t * a(j,k);
b(L,k) = b(L,k) + t * b(j,k);
end
end
end
end
break
end
% Display warning if a row full of zeros is found
if a(i,j) == 0
disp('Warning: Singular Matrix')
b = 'error';
return
end
end
% Show the evolution of the input matrix, so that we can
% confirm that it became an identity matrix.
a
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar