Problem plotting with 4 columns

10 ビュー (過去 30 日間)
D.J
D.J 2018 年 9 月 1 日
コメント済み: jonas 2018 年 9 月 1 日
Hi all, I am trying to plot this function, but getting so many errors. I first got this error: "A numeric or double convertible argument is expected" So I converted the table to array, then I got this error: "Size mismatch in Param Cell / Value Cell pair" I ran out of ideas ! Basically, I need x to be the dates (using standard formats, all days showing) y to show 3 columns: min, max and difference between them Here is my code, I have also attached the data file. Any help would be highly appreciated ! Thanks a lot!
clear
clc
Table_Q7=readtable('Test_data7.csv');
x_tbl=Table_Q7(6:end,2);
%tbl 2 array
x=table2array(x_tbl);
%ymin tbl2array
y_min_tbl=Table_Q7(6:end,3);
y_min=table2array(y_min_tbl);
%ymax tbl2array
y_max_tbl=Table_Q7(6:end,4);
y_max=table2array(y_max_tbl);
%y difference between max and min
y_diff_tbl=Table_Q7(6:end,5);
y_diff=table2array(y_diff_tbl);
%y=table2array(y_tbl)
plot(x,[y_max,y_min,y_diff])

採用された回答

jonas
jonas 2018 年 9 月 1 日
編集済み: jonas 2018 年 9 月 1 日
Here's a solution using textscan instead of readtable
fid=fopen('Test_data7.csv')
formatSpec='%s%d%d%d';
out=textscan(fid,formatSpec,...
'delimiter',',',...
'MultipleDelimsAsOne',true,...
'collectoutput',true,...
'HeaderLines',6)
fclose(fid);
t=datetime(out{1});
data=out{2};
plot(t,data)
  2 件のコメント
D.J
D.J 2018 年 9 月 1 日
Perfect ! Thanks a million ...Much appreciated !!
jonas
jonas 2018 年 9 月 1 日
No problem, happy to help!

サインインしてコメントする。

その他の回答 (2 件)

jonas
jonas 2018 年 9 月 1 日
編集済み: jonas 2018 年 9 月 1 日
The problem is with your data import, as the csv is a bit messy. This is the cleanest import out of many attempts. Results attached.
opts=detectImportOptions('Test_data7.csv','Delimiter',',','NumHeaderLines',5)
opts.ExtraColumnsRule='ignore'
opts.SelectedVariableNames={'Date','MinTemp','MaxTemp','DiffTemp'}
T=readtable('Test_data7.csv',opts);
TT=table2timetable(T);
plot(TT.Date,TT.Variables)
  12 件のコメント
jonas
jonas 2018 年 9 月 1 日
Thanks. That output is not very useful. I'll come back with another solution shortly.
jonas
jonas 2018 年 9 月 1 日
Posted a separate answer using textscan. I understand your concern. I used release 2013a for 3-4 years until I was finally forced to update as I needed to use the latest image processing functions. I saved the old release just-in-case, but I have never had to use it :)

サインインしてコメントする。


D.J
D.J 2018 年 9 月 1 日
Thanks a lot Jonas. I really appreciate your help !
  1 件のコメント
jonas
jonas 2018 年 9 月 1 日
If any one of the answers solved your problem please accept it ;)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by