Textscan difficulties opening file.

2 次查看(过去 30 天)
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.

采纳的回答

Stephen23
Stephen23 2018-8-10
编辑:Stephen23 2018-8-10
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 个评论
ethan campbell
ethan campbell 2018-8-10
编辑:Stephen23 2018-8-10
even when I take the full path,
C:\Users\KumarN\Desktop\VisualFieldAnalysis\data\subjects\0782en\Visual Fields\DVF\DVF 9_4_08\0782en_OD_monoc_9_4_08.csv
and assign it to dpt in the fopen function, the msg variable comes out with a value of 'No such file or directory'... could this be a problem with the code or is it likely an issue with where the file is originally located?
Stephen23
Stephen23 2018-8-10
编辑:Stephen23 2018-8-10
"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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by