Error using plot Invalid data argument (Data from Excel)

35 views (last 30 days)
Nate Mays
Nate Mays on 9 Mar 2021
Commented: Nate Mays on 10 Mar 2021
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

Sign in to comment.

Accepted Answer

ANKUR KUMAR on 10 Mar 2021
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)) = {''};
time=cellfun(@(x) datetime(datestr(datenum(x,'dd-mmm-yy'))) ,weather_data(:,1),'uni',0);
Hope this helps.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by