Textscan difficulties opening file.
2 views (last 30 days)
Show older comments
Trying to read a file but failing miserably. File that I'm trying to open is attached. Here's what I'm doing:
fnm = '0782en_OD_monoc_9_4_08.csv.analized'
fid = fopen(fnm,'r')
textData = textscan(fid,'%s%s%s%s%s%s%s%s%s%f%f','delimiter','\t');
When opened on the occasion that it works, it comes up with a 1x11 cell with none of the data inside because the s's and f's inside of the percent symbols are likely off of what they should be. If someone could point me in the right direction for what I should put in the percents/ give me a script to open this file, that would be much appreciated. I highly recommend trying to open the attached file yourself to see if there are other issues.
Thanks all.
Edit: I'd be most appreciative if someone were to just dump the entire list of commands that I should perform into the comments. Would make it way easier for a noob like me to follow.
0 Comments
Accepted Answer
Stephen23
on 10 Aug 2018
Edited: Stephen23
on 10 Aug 2018
Something like this will get you started:
opt = {'Delimiter','\t','HeaderLines',1,'CollectOutput',true};
fmt = '%s%f%f%f%f%f%f%f%f%f%f%f%f%s';
[fid,msg] = fopen('0782en_OD_monoc_9_4_08_csv_analized.txt','rt');
assert(fid>=3,msg)
C = textscan(fid,fmt,opt{:});
fclose(fid);
% Remove NaN rows:
idx = ~all(isnan(C{2}),2);
pth = C{1}(idx,:);
mat = C{2}(idx,:);
rgb = C{3}(idx,:);
Imports this data:
>> pth
pth =
'C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv'
'C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv'
'C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv'
... lots of lines
'C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv'
'C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv'
'C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv'
>> mat
mat =
2 800 600 1668 1242 1000 0 0 14 -3 0 0
2 800 600 1668 1242 1000 0 0 104 -75 0 0
2 800 600 1668 1242 1000 0 0 55 -59 0 0
2 800 600 1668 1242 1000 0 0 158 1 0 0
2 800 600 1668 1242 1000 0 0 163 -47 0 0
2 800 600 1668 1242 1000 0 0 160 43 0 0
... lots of lines
2 800 600 1668 1242 1000 0 0 21 -12 0 0
2 800 600 1668 1242 1000 0 0 17 -1 0 0
2 800 600 1668 1242 1000 0 0 18 5 0 0
>> rgb
rgb =
'java.awt.Color[r=255,g=0,b=0]'
'java.awt.Color[r=255,g=0,b=0]'
'java.awt.Color[r=255,g=0,b=0]'
'java.awt.Color[r=255,g=0,b=0]'
... lots of lines
'java.awt.Color[r=0,g=0,b=255]'
'java.awt.Color[r=0,g=0,b=255]'
'java.awt.Color[r=0,g=0,b=255]'
'java.awt.Color[r=0,g=0,b=255]'
'java.awt.Color[r=0,g=0,b=255]'
4 Comments
Stephen23
on 10 Aug 2018
Edited: Stephen23
on 10 Aug 2018
"even when I take the full path ... and assign it to dpt in the fopen function, the msg variable comes out with a value of 'No such file or directory'"
The dpt variable should not include the filename, like you are doing. It should only include the path itself, like my answer shows. The filename is stored in the variable fnm.
To be honest, there is something strange with the file path: why is the same path stored in the first column of the file itself? This is highly unusual.
More Answers (0)
See Also
Categories
Find more on Text Files 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!