how to read data and put them into separate line?

조회 수: 4 (최근 30일)
f moradi
f moradi 2018년 6월 21일
댓글: f moradi 2018년 6월 21일
Hello I read a file with the
Training=fscanf(fileid,'%c %c%c %c\n'); command.
But why dont enter a new row to read the next line and place the entire file in a character? What should I do to separate the row into a row and in a separate row?
EDIT: f moradi's "Answer" moved here:
my file Inside zip file. I write this code. but I want separete lines.
fileid=fopen ('C:\Users\f\Documents\MATLAB\me\noisy_train.ssv');
Training=fscanf(fileid,'%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n');
  댓글 수: 7
dpb
dpb 2018년 6월 21일
OK, that helps.
Are the lengths of the records known a priori or do you have to figure that out? If known, it's trivial making use of that, otherwise you needs must read in a way to count records to shape the output in the array.
f moradi
f moradi 2018년 6월 21일
the lengths of the records are known a priori

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

채택된 답변

dpb
dpb 2018년 6월 21일
In that case (known record length)
>> L=23; % define record length
>> fmt=repmat('%c',1,L); % format string given length
>> fid=fopen('train.txt');
>> data=cell2mat(textscan(fid,fmt,'collectoutput',1)) % read the file
data =
14×23 char array
'1fyyfffcbpebkkbppwolhyg'
'1fsbtffcbptbfswwpwophvg'
'0fyetnfcbutbsspwpwopkvd'
'1fyyfffcbpebkkbbpwolhvd'
'0fygtnfcbutbssggpwopnvd'
'0bywtlfcbkecsswwpwopnnm'
'0fyetnfcbutbsswgpwopnyd'
'0fswfnfwbhtesswwpwoensg'
'0xswfnfwbntefswwpwoensg'
'0xfgfnfcnneesswwpwopkyu'
'1xygfffcbgebkknppwolhvd'
'1xfgfffcbhebkkbppwolhyp'
'1xfgfffcbpebkknbpwolhyd'
'0xyntnfcbwtbssgwpwopnyd'
>> fid=fclose(fid);
  댓글 수: 1
f moradi
f moradi 2018년 6월 21일
Your answer was very good. Thank you very much:)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by