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

Jan
Jan 2011년 5월 4일
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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 5월 4일

0 개 추천

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

Dana Schneider
Dana Schneider 2011년 5월 5일
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 2011년 5월 5일
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'};

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by