making a graph of using date as x axis.
Show older comments
My data

I am struggling on making a graph of using date as x axis.
My code is below:
csv_file = fopen('test.csv','r');
formatSpec = '%s%s%s';
C = textscan(csv_file, formatSpec, 'Delimiter', ';');
fclose(csv_file);
%char to double
temp = str2double(C{1,3});
%remove NaN in temp
%double to logical
idx = ~isnan(temp(:,1));
%keep remove nan
FlowTemp = temp(idx,1);
x= C{1,1} <== does not work.
plot(x,FlowTemp)
6 Comments
Bob Thompson
on 11 Mar 2019
What do you mean by 'does not work?' Do you get an error message? How is it different than what you expected?
I'm assuming that the command itself works, but that you aren't able to plot the results. This is most likely because x is an array of strings, not of dates and times. You should use datetime() to convert into a proper date and time format.
Ming-En Han
on 11 Mar 2019
Bob Thompson
on 11 Mar 2019
Ok, so it seems likely that you have another layer of cells within C. I would suggest trying something like the following:
x = datetime([C{1,1}{:}]);
I'm not positive it will work, cells can be tricky like that. If that doesn't work you might try:
x = datetime(cell2str(C{1,1})); % I think cell2str is the command
Ming-En Han
on 11 Mar 2019
Adam Danz
on 11 Mar 2019
Could you share the value of C{1,1} (at least the first 5-6 values)?
Ming-En Han
on 11 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Dates and Time 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!


