How can I solve the eror " Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier. " for this code ?

8 views (last 30 days)
function [load_time_stamp, load_value]=get_the_actual_demand_data()
filename = 'dee1.csv'; delimiter = ','; startRow = 2;
formatSpec = '%s%*s%[^\n\r]'; fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1);
%dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
load_time_stamp = dataArray{:, 1};
fclose(fileID);
formatSpec = '%*s%f%[^\n\r]'; fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1);
%dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
load_value = dataArray{:, 1};
fclose(fileID);
end
  4 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!