Hello,
I'm currently just trying to import a csv file into matlab so that I may plot columns 1 and 2.
I have the following code below which checks for any CSVs files in a given directory and imports their data.
However, the problem I'm encountering is that given the format of the time in my CSV file, it yields an error claiming.
Mismatch between file and format character vector.Trouble reading 'Numeric' field from file (row number 1, field number 2) ==> :00:00,2\n
This problem is solved if I just skip the time column entirely. But I need to import the time and I can't just skip the time column.
Is there any way I can import the time given its current formatting? I have the CSV file attached to this post for reference.
The code I'm running:
myFolder = 'C:\Users\User1\Desktop\Search here\Batch CSVs';% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return;end%Output file type to save plot as
filetype = '.fig';% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.csv'); % File extension to search for
theFiles = dir(filePattern);for k = 1 : length(theFiles) baseFileName = theFiles(k).name; fullFileName = fullfile(myFolder, baseFileName); %Creates two 2-d plots
dataArray = csvread(fullFileName,1,0); %Grab data starting from row 1 column 0
time = dataArray(:,1); weight = dataArray(:,2); end
Best Answer