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 次查看(过去 30 天)
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?

回答(1 个)

Walter Roberson
Walter Roberson 2018-3-20
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 个评论
javad amoli
javad amoli 2018-3-21
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by