I want to plot my outputs , X vector is text format ( for example 10/3/2015-8:00-8:15 ) and my Y vector is number . how should i plot them ? I got error on text format

5 views (last 30 days)
I got error on text format , seem that both of the vector must be number .
another Q : how can I change the shape of the graph?

Answers (1)

Walter Roberson
Walter Roberson on 20 Mar 2018
You need to convert those time strings to datenum or datetime objects, as we discussed with you in https://www.mathworks.com/matlabcentral/answers/382006-what-is-this-eror-and-what-does-it-mean-and-how-can-i-solve-it#answer_304563
  1 Comment
javad amoli
javad amoli on 21 Mar 2018
I know it, I did my changes on it, I don't know why it doesn't work . look at my code and my CSV file plz.
function [Time_stamp, Original_load_kw]=Plot()
filename = 'Dterministic_Output_data.csv';
delimiter = ',';
startRow = 2;
formatSpec = '%{yyyy-mm-ddTHHMMSS}D%*s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-2);
%dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
a = datestr(dataArray{1,1},'yyyy-mm-ddTHHMMSS');
Time_stamp = cellstr(a);
fclose(fileID);
formatSpec = '%*s%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-2);
%dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
Original_load_kw = dataArray{:, 1};
fclose(fileID);
X = datenum( Time_stamp,'yyyy-mm-ddTHHMMSS');
stem( X, Original_load_kw );
datetick('x','yyyy-mm-ddTHHMMSS'),
end

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!