how to read data and put them into separate line?

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 commentaires

KSSV
KSSV le 21 Juin 2018
How is your text file?
f moradi
f moradi le 21 Juin 2018
I attached it.
f moradi
f moradi le 21 Juin 2018
what happened?
dpb
dpb le 21 Juin 2018
Attach a small section of the actual file so we can see it w/o extra machinations.
Even better would be to illustrate just what it is you really would like the result to be from that data...it's certainly not clear to me what the right answer would be.
f moradi
f moradi le 21 Juin 2018
Modifié(e) : dpb le 21 Juin 2018
I want to put this data into a matrix , like below:
1 f y y f f f c b p e b k k b p p w o l h y g
1 f s b t f f c b p t b f s w w p w o p h v g
0 f y e t n f c b u t b s s p w p w o p k v d
1 f y y f f f c b p e b k k b b p w o l h v d
dpb
dpb le 21 Juin 2018
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 le 21 Juin 2018
the lengths of the records are known a priori

Connectez-vous pour commenter.

 Réponse acceptée

dpb
dpb le 21 Juin 2018
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);

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by