필터 지우기
필터 지우기

Error using plot Invalid data argument (Data from Excel)

조회 수: 2 (최근 30일)
Nate Mays
Nate Mays 2021년 3월 9일
댓글: Nate Mays 2021년 3월 10일
Hello,
I'm having a problem as I try to plot two columns of data from excel (temperature over time). I keep getting the following error. (Error using plot
Invalid data argument.) My code is below.
%%Use readtable for importing data from excel%%
WData = readtable('WeatherData1.xlsx');
%(1)Determine Temperature Variations throughout the year.
%Extact High temperatures
TempH = WData{2:366,2};
y = TempH;
%Extract Low temperatures
TempL = WData{2:366,4};
%Extract Avg Temperatures
Tempavg = WData{2:366,3};
%Extract the dates
Dates = WData{2:366,1};
x = Dates;
%plot the temperture variations over the year
plot(x,y)
  댓글 수: 23
Walter Roberson
Walter Roberson 2021년 3월 10일
You would get that if you tried to read a header. You might need to use detectImportOptions first which was not yet automatic in your release.
Nate Mays
Nate Mays 2021년 3월 10일
Appreciate it will do.

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

채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2021년 3월 10일
You can generate dates as per the values in the excel sheet. This won't throw an error for dimension mismatch.
[~, ~, weather_data] = xlsread('WeatherData1.xlsx','Sheet1','A1:B367');
weather_data(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),weather_data)) = {''};
weather_data=weather_data(3:end,:);
time=cellfun(@(x) datetime(datestr(datenum(x,'dd-mmm-yy'))) ,weather_data(:,1),'uni',0);
temp=weather_data(:,2);
plot(cat(1,time{:}),cell2mat(weather_data(:,2)))
Hope this helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by