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일

0 개 추천

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일

0 개 추천

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

D.J
D.J 2018년 9월 1일
I am getting this error: Undefined function or variable 'detectImportOptions'
D.J
D.J 2018년 9월 1일
I am afraid still not working. Getting the same error ..
D.J
D.J 2018년 9월 1일
Is it actually working at your end?
jonas
jonas 2018년 9월 1일
편집: jonas 2018년 9월 1일
What MATLAB release are you using? Can you paste the first rows of the output of readtable, assuming that you are able to use detectImportOptions? It's working fine on my end yep.
D.J
D.J 2018년 9월 1일
I am using Matlab R2015b I have never used deteImportOptions. I tried to find details about it in the documentation, but there is nothing there !
jonas
jonas 2018년 9월 1일
편집: jonas 2018년 9월 1일
Introduced in R2016b
A few options:
  • Maybe we can solve it without a clean import. Can you copy-paste the first rows of your readtable output?
  • Update your MATLAB release
  • We can use csvread or textscan instead.
D.J
D.J 2018년 9월 1일
편집: D.J 2018년 9월 1일
This is what I am getting:
Undefined function or variable 'detectImportOptions'.
Error in plot_7_T (line 24)
opts=detectImportOptions('Test_data7.csv','Delimiter',',','NumHeaderLines',5)
>>
jonas
jonas 2018년 9월 1일
편집: jonas 2018년 9월 1일
Well, I mean in your original code. Output of this:
Table_Q7=readtable('Test_data7.csv');
Only copy first 2-3 rows, or this comment chain becomes hard to read.
Is this what you need? if you can't read it, I attached a snapshot of it:
'ttt' '' '' '' '' NaN NaN NaN NaN NaN
'ttt' '' '' '' '' NaN NaN NaN NaN NaN
'ttt' '' '' '' '' NaN NaN NaN NaN NaN
'' '' '' '' '' NaN NaN NaN NaN NaN
'' 'Date' 'MinTemp' 'MaxTemp' 'DiffTemp' NaN NaN NaN NaN NaN
'' '1/07/2017' '2.2' '19.7' '17.5' NaN NaN NaN NaN NaN
'' '2/07/2017' '2' '21' '19' NaN NaN NaN NaN NaN
'' '3/07/2017' '4.9' '21.4' '16.5' NaN NaN NaN NaN NaN
'' '4/07/2017' '9.5' '25.3' '15.8' NaN NaN NaN NaN NaN
'' '5/07/2017' '8.6' '25' '16.4' NaN NaN NaN NaN NaN
'' '6/07/2017' '5.5' '21.8' '16.3' NaN NaN NaN NaN NaN
'' '7/07/2017' '9.5' '18.9' '9.4' NaN NaN NaN NaN NaN
D.J
D.J 2018년 9월 1일
편집: D.J 2018년 9월 1일
I don't want to take the risk of updating my matlab. I am worried the software might be stuffed up completely. It is the student version from the university, and if I get an technical problems due to the update, I won't be able to get any help during the weekend.
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일

0 개 추천

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 ;)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

D.J
2018년 9월 1일

댓글:

2018년 9월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by