Trouble with permissions for fopen and textscan

I'm looking at reading in text data from a data I took in a .txt format from a data acquisition unit and I'm having trouble reading it into MatLab. The following is what my function looks like:
%
function [ data0 ] = NIopen( filename )
fileID=fopen(filename);
data=textscan(fileID, '%s %s %s %s %s %s %s %s');
data=data(3);
data=data{1,1};
data=data(2:end);
data0=str2double(data(:));
fclose('all');
end
I'm looking at just getting the third column of data (date, time, data, date, time, data), but for some reason, I keep getting the following message referencing fopen() not working for some reason.
NIopen('Combo_1_2_70.txt');
>>NIopen('Combo_1_2_70.txt');
??? Error using ==> textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> NIopen at 7
data=textscan(fileID, '%s %s %s %s %s %s %s %s');
And when that gets resolved (I change the permissions to 'r+'), textscan() spits out 8, 0x1 [] cells. This worked this morning and now it's not, leading me to wonder if it's a permissions issue, but I'm not sure how to proceed. Any help would be very much helpful!
Thanks!

Answers (1)

Try replacing this line
fileID=fopen(filename);
with this:
if ~exist(filename)
errorMessage = sprintf('Error: file %s not found. Click OK to exit.\n', filename);
fprintf('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
return;
end
fileID=fopen(filename)
fprintf('fileID = %d\n', fileID);

2 Comments

Why does this 'Invalid permission' message arise at all? What does it mean?
Anuradha Bhattacharya, please post an exact copy of the error message. Also, try
[fileID, msg] = fopen(filename, 'rt');
if fileID < 0
error('Failed to open file "%s" because "%s"', filename, msg);
end

Sign in to comment.

Categories

Asked:

on 7 Jun 2013

Commented:

on 22 Sep 2016

Community Treasure Hunt

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

Start Hunting!