isspace finds wrong spaces in ascii file

Hi.
I am using the function below to create separations in my line file. It used to work just fine, however for some reason it now sets the spaces at non-space places (e.g., 75666 83929 92920---created '5666' '3929' '2920').
[rows] = size( line );
for R = 1:rows
sep {R,1} = find( isspace ( line{R} ) );
end
Any advise would be highly appreciated.
Best Regards Dana

1 comentario

Jan
Jan el 4 de Mayo de 2011
I do not see how the posted code converts "75666 83929 92920" to '5666' '3929' '2920'.
After "rows = size(line)" the variable "rows" is a vector. Therefore "for R=1:rows" does not what you expect most likely.
Please explain the input exactly (what is "line"?) and the wanted output.

Iniciar sesión para comentar.

 Respuesta aceptada

Oleg Komarov
Oleg Komarov el 4 de Mayo de 2011
If you're trying to split that sequence:
% example input:
line = {'75666 83929 92920'
'75466 39293 92320 32424'};
tks = regexp(line,'\d+','match');
% This concatenation will work if the number of sequence is equal per each row
tks = cat(1,tks{:});

2 comentarios

Dana Schneider
Dana Schneider el 5 de Mayo de 2011
Thanks Oleg.
I am not super great with codes so excuse the question if it strikes you as basic.
What would this do exactly? I was thinking perhaps I could just add somehow an extra space in front of my number strings to let the function find another space.
Any idea how I could do that?
Oleg Komarov
Oleg Komarov el 5 de Mayo de 2011
The code I posted takes a cell-array of strings and processes string by string (contained in each cell) by separating the numerical sequences whenever a space occurs.
Lets say you have:
line = {'75666 83929 92920'}
You will get:
tks = {'75666' '83929' '92920'};

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by