I have a text file in the format as
65535 ,10,10000,31737,31223,32765,33280,32765,31480,31223,31223,31223,31223,31480, 65535 ,40,50000,31737,31223,32765,33280,32765,31480,31223,31223,31223,31223,31480........
It is delimited by 65535 , I want to separate these blocks of data , can u suggest me how to do that.
Regards

댓글 수: 1

per isakson
per isakson 2014년 8월 18일
Are there no line-breaks? Is it all in one row?

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

 채택된 답변

Image Analyst
Image Analyst 2014년 8월 18일

0 개 추천

This way is pretty easy to follow and understand:
% Get the string from reading the file.
% (Hard coded below for the demo.)
str = '65535 ,10,10000,31737,31223,32765,33280,32765,31480,31223,31223,31223,31223,31480, 65535 ,40,50000,31737,31223,32765,33280,32765,31480,31223,31223,31223,31223,31480'
% str(str == ' ') = [] % Remove spaces.
numbers = cell2mat(textscan(str, '%d,'))
% Split up into different blocks
delimiters = find(numbers == 65535)
for k = 1 : length(delimiters)
index1 = delimiters(k)+1;
if k == length(delimiters)
index2 = length(numbers);
else
index2 = delimiters(k+1) - 1;
end
% Assign this block to one cell of a cell array.
outputs{k} = numbers(index1:index2);
end
% Display in command window:
celldisp(outputs);
Though, if you want a cryptic one-liner, someone will give you one.

추가 답변 (0개)

카테고리

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

태그

질문:

2014년 8월 18일

댓글:

2014년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by