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 Comment

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.

Sign in to comment.

 Accepted Answer

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 Comments

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?
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'};

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!