Import an oddly shaped txt file

1 view (last 30 days)
ayat
ayat on 29 Mar 2016
Answered: KSSV on 29 Mar 2016
I have a txt file that is with a weird shape as you can see in the attached. When I use the import feature in matlab and choose nemeric matrix, the imported matrix looks like it should (each value allocated to the correct number on the second row). I don`t know how to replicate that in code. On a side note, is it possible to replace the "," with "." and then import?

Answers (1)

KSSV
KSSV on 29 Mar 2016
clc; clear all ;
file = 'B00001.txt' ;
fid = fopen(file,'r') ;
S=textscan(fid,'%s','delimiter','\n');
fclose(fid) ;
S = S{1} ;
All the file contents will be saved in cell S. You can do what ever you want from S.
Note that there are many other ways to read a file.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!