Having trouble running this code. Two errors with the script possibly could be a column of characters that can not be converted but not sure. Any help is appreciated. Thank You

Error using regexp
The 'STRING' input must be either a char row vector or a cell array of char row vectors.
Error in import_delsys_csv_octave (line 14)
varnames = regexp(columnnames, ',', 'split');
Error in bme6500_lab4_startcode_v1 (line 16)
[delsys_info, sensor] = import_delsys_csv_octave(delsys_filename);
CODE
close all
clearvars
clc
% Select file to analyze
[FileName,PathName] = uigetfile('*.csv');
delsys_filename = [PathName FileName];
%%load Delsys data
[delsys_info, sensor] = import_delsys_csv_octave(delsys_filename); ##ERROR OCCURS HERE
function[delsys,sensor] = import_delsys_csv_octave(delsys_filename)
file_id = fopen(delsys_filename);
fclose(file_id);
header = []; ct = 1;
while length(header) ~= 1
header = fgetl(file_id);
delsys.sysinfo{ct} = header;
ct = ct+1;
end
firstdatarow = ct;
columnnames = fgetl(file_id);
varnames = regexp(columnnames, ',', 'split');
emptycol = strcmp(varnames, ''); #ERROR ALSO OCCURS HERE
varnames(emptycol) = [];
N = length(varnames);

Answers (1)

Abdul - I think that you are trying to get the column names too late
fclose(file_id);
header = []; ct = 1;
while length(header) ~= 1
header = fgetl(file_id);
delsys.sysinfo{ct} = header;
ct = ct+1;
end
firstdatarow = ct;
columnnames = fgetl(file_id);
as you have already closed the file before you try to get the header (within the while loop) or the columnnames. I recommend that you delay closing the file until you have finished extracting the lines from it.
Also, consider using the debugger so that you can step through your code and see what is happening at each line.

Products

Asked:

on 16 Nov 2017

Answered:

on 16 Nov 2017

Community Treasure Hunt

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

Start Hunting!