Borrar filtros
Borrar filtros

separate codes work, together don't

2 visualizaciones (últimos 30 días)
alexaa1989
alexaa1989 el 23 de Ag. de 2014
Respondida: Matz Johansson Bergström el 23 de Ag. de 2014
hi everyone I have written a code which is part of an algorithm and it is greatly working but when I put the exact same code in the algorithm it causes problem and the error refers to the code I have just put in
here is the code
ll=1;
for i=1:sk(1)
for j=1:sk(2)
if k(i,j)>0.5
k1(i,j)=k(i,j);
else
k1(i,j)=k0(ll);
ll=ll+1;
end
end
end
when I put it in the algorithm the ( ll ) counts more than numel(k0) but when I run it separately it works.
what is wrong with it?

Respuesta aceptada

Matz Johansson Bergström
Matz Johansson Bergström el 23 de Ag. de 2014
I don't know the values of the variables you are using but this seems to work
n = 5;
k = rand(n,n);
sk = size(k)
k0 = 1:numel(k) %must be (maximum) the number of elements in k
ll = 1;
for i=1:sk(1)
for j=1:sk(2)
if k(i,j)>0.5
k1(i,j)=k(i,j);
else
k1(i,j)=k0(ll);
ll=ll+1;
end
end
end

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by