Anyone know why I am recieving this error?

1 visualización (últimos 30 días)
Cem SARIKAYA
Cem SARIKAYA el 28 de Dic. de 2018
Comentada: Image Analyst el 28 de Dic. de 2018
z=1;
m=1;
at = 1;
data = rand(7004829, 1);
for k = 2 : at : length(data)
if k ~= (k+1)
index1=k;
y(m,1) = data(index1:z);
z = k;
m = m+1;
end
end
  1 comentario
Walter Roberson
Walter Roberson el 28 de Dic. de 2018
Please do not close questions that have an Answer.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Dic. de 2018
This is also useless:
if k ~= (k+1)
Can you tell me when k will EVER be equal to k+1? Answer: never. So the condition is always true. That wouldn't cause an error though - it's just bad programming.
Also, id, when you do get around to defining it. Must be a 2-D matrix.
And you might want to preallocate y in advance, though it's not necessary.
And finally, there are no comments. All professional programmers put comments in their code to help them understand later what they did, or to help others understand what they did. I don't really know what you're trying to do. Maybe there is a function or one vectorized line of code to do it, but since there are no comments, I don't know.
  3 comentarios
Walter Roberson
Walter Roberson el 28 de Dic. de 2018
image analyst: redefine length as uint8(255). when k reaches uint(255) then k~=k+1 would be false.
... it could happen !
Image Analyst
Image Analyst el 28 de Dic. de 2018
Walter - true. Cem, if you just want to extract matrices that have only the ID number and no other numbers except zero where that number is not the desired number, you can see this example:
m = randi(3, 4, 6) % Sample ID array
m1 = double(ismember(m, 1)) % Get just the 1's
m2 = 2 * double(ismember(m, 2)) % Get just the 2's
m3 = 3 * double(ismember(m, 3)) % Get just the 3's
You'll see
m =
1 1 2 1 3 2
1 1 3 2 3 2
1 2 3 3 2 1
1 3 2 3 3 2
m1 =
1 1 0 1 0 0
1 1 0 0 0 0
1 0 0 0 0 1
1 0 0 0 0 0
m2 =
0 0 2 0 0 2
0 0 0 2 0 2
0 2 0 0 2 0
0 0 2 0 0 2
m3 =
0 0 0 0 3 0
0 0 3 0 3 0
0 0 3 3 0 0
0 3 0 3 3 0
Is that what you're hoping to do?

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 28 de Dic. de 2018
Editada: madhan ravi el 28 de Dic. de 2018
  • id is not defined
  • if condition is superfluos though , always k is not equal to k + 1
  • y needs to be preallocated
  • y can be preallocate as a cell to further avoid error ( unable to perform ....due to size)
  2 comentarios
Cem SARIKAYA
Cem SARIKAYA el 28 de Dic. de 2018
Editada: Cem SARIKAYA el 28 de Dic. de 2018
is matlab work concurrent assignment? i need this code not concurrent assignment like c++, and i fix id

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB 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