Borrar filtros
Borrar filtros

separating strings one by one

1 visualización (últimos 30 días)
Valeria Chacon
Valeria Chacon el 26 de Oct. de 2016
Comentada: Star Strider el 26 de Oct. de 2016
N=length(str);
count=1;
for k=1:N
x=str2double(str(k));
if isnan(x)==0
str(count)=x(k);
count=count+1;
disp(x);
end
end
This is currently the code I have right now but it keeps giving me an error because the "index exceeds matrix dimensions on the line: str(count)=x(k); What am I doing wrong?

Respuesta aceptada

Star Strider
Star Strider el 26 de Oct. de 2016
your ‘x’ variable is a scalar, by definition a (1x1) ‘array’. So ‘x(k)’ is only valid for x=1.
This will likely eliminate that error:
str(count)=x;
  2 comentarios
Valeria Chacon
Valeria Chacon el 26 de Oct. de 2016
is there any way that I can call for the 4th and 8th number of this code??? like if my result after it is:1256893490 then how can I pull out the 4th and 8th number of it? Thank you!
Star Strider
Star Strider el 26 de Oct. de 2016
My pleasure!
I don’t know what ‘str’ is.
I assume that you would address them as:
str(4)
str(8)
respectively.
You can assign them as separate variables, but it is best to simply refer to them as elements of the vector.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing 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