I am trying to combine two .cvs files into one. The script I have so far works to write the tables to Excel files…
[Timestamps,Samples] = Nlx2MatCSC('C:\Users\HomePC\Desktop\CSClfp1.ncs',[1 0 0 0 1],0,1,[]); % imports CSC.ncs into MATLAB
Samples = Samples';Timestamps = Timestamps'; Samples = Samples(:,256); Samples = table(Samples); writetable(Samples,'./Samples.csv'); Timestamps = table(Timestamps); writetable (Timestamps, './Timestamps.csv');
This effectively writes the matrices to two separate .csv files. However, it is somewhat annoying to copy the single column of data from Timestamps.csv and paste it into Samples.csv every single time.
I tried adding this:
csv1 = csvread('C:\Users\HomePC\Desktop\Samples.csv');csv2 = csvread('C:\Users\HomePC\Desktop\Timestamps.csv);allCsv = [csv1;csv2]; % Concatenate vertically
csvwrite(SamplesandTimestamps, allCsv);
at the end of the script, but MATLAB returns the following errors:
Error using dlmread (line 147)Mismatch between file and format character vector.Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> Samples\nError in csvread (line 48) m=dlmread(filename, ',', r, c);Error in NCStoExcel (line 25)csv1 = csvread('C:\Users\HomePC\Desktop\Samples.csv');
I understand csvread only reads numeric data, but I can't use
Samples.Properties.VariableNames(1) = {1};
I think this does not work because it is not writing "1" as an integer.
Anyone know how I could solve this? Sorry for the length of the post!
Best Answer