ERROR: Conversion to double from cell is not possible
Show older comments
Hi! I've perused all of the questions that had the same answer, but their recommendations did not work
Used:
- char()
- str2double()
- cell2mat()
- and some other cell2 and different read
What it does fine:
- finds all files in current directory that are .csv (only data files currently in my current directory)
- gets the file names and counts how many .csv files are in there
- starts for loop at 1
- accesses the first csv file and scans column 5 across all rows (should be comparing each integer to be greater than 90)
- I then hit an error message
- makes folder in current directory if there's not a folder
- saves csv file (with project name and today's date--> this was super cool) in that directory and makes you go back to the original directory
ERROR
Line 25: fullData(:,cur_file) = [filelist(1,cur_file);count]
Your help is very appreciated! I am trying to see how much more data I need to collect with this information.
filelist=dir('*.csv'); %directory of .csv files
filelist={filelist.name}; %transfor6med into a list
%filelist = char(filelist)
num_files=length(filelist); %how many subjects?
fullData=[]; %Initialize empty data
%%
count =[];
for cur_file=1:num_files, %for each file
count = 0; %initialize and set to 0 each loop
cur_data=readmatrix(filelist{cur_file}); %read in current file
%cur_data=filelist(cur_file); %read in current file
%cur_data=str2double(cur_data);
for eachRow=1:length(cur_data(:,5)), %
if cur_data(eachRow,5)>90;
count = count+1;
end
end
fullData(:,cur_file) = [filelist(1,cur_file);count]
%fullData(:,cur_file) = [filelist(1,cur_file) count]
%fullData=[fullData ; count]; %add current file under all previous files
%for all numbers in Progress column, if number in row >= 60, count
end
%%
fullData2=fullData'
% convert matrix array to a table with headers called...
output2 = array2table(fullData2, 'VariableNames',{'FileName','QualifyingCount'})
% checks to see if folder exists in current directory; make if not
if not(isfolder('dataCollectionProgress')),
mkdir('dataCollectionProgress')
end
%find today's date
%date = datetime("today")
d = date
DateString = datestr(d)
projectName = 'ProjectName'
fileType = '.csv'
outputName = [projectName DateString fileType]
%%
% Export table to csv in same directory
%writetable(output2, 'IdentifyingObjects_' num2str(date) '.csv');
cd ./dataCollectionProgress %change current directory to folder called this from current
writetable(output2, outputName);
cd ../ %go back to previous directory
Answers (1)
MissEgg
on 9 Sep 2020
0 votes
Categories
Find more on String Parsing 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!