Error with reading excel file

9 Ansichten (letzte 30 Tage)
Anders Vigen
Anders Vigen am 19 Feb. 2021
Beantwortet: Anders Vigen am 23 Feb. 2021
start_date = datetime(2020,1,2,0,0,0);
end_date = datetime(2020,1,3,0,0,0);
demand = load_demand('Demand_timeseries_1hourResolution.xlsx',start_date,end_date);
figure (21)
plot(demand.Time, demand.Values)
xlabel('Time');
ylabel('Demand [MW]');
title('Demand')
I'm having bit of a frustrating issue with my scrript. I wantto read excel file in the same folder where I have my matlab file, however it keeps giving me the same error
'Unrecognized function or variable 'load_demand''
The script works for everybody else but me, so I can't find the problem.
I hope somebody can help me
  13 Kommentare
Anders Vigen
Anders Vigen am 20 Feb. 2021
It gives me
built-in (C:\Program Files\MATLAB\R2020b\toolbox\matlab\general\which)
'load_demand' not found.
Unrecognized function or variable 'load_demand'.
Error in main_2 (line 136)
demand = load_demand('Demand_timeseries_1hourResolution.xlsx',start_date,end_date);
And this was the script I put in
builtin('which', 'which')
which load_demand
demand = load_demand('Demand_timeseries_1hourResolution.xlsx',start_date,end_date);
Walter Roberson
Walter Roberson am 20 Feb. 2021
Okay, and what about on your colleague's computer? What shows up on there?
At this point, I can pretty much predict an implimentation of the function:
function demand = load_demand(filename, start_date, end_date)
T = readtable(filename);
mask = isbetween(T{:,1}, start_date, end_date);
demand = T(mask,:);
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Anders Vigen
Anders Vigen am 23 Feb. 2021

Weitere Antworten (1)

Ani Singh
Ani Singh am 21 Feb. 2021
From the error "'Unrecognized function or variable 'load_demand" looks like you do not have "load_demand" user-defined function implementation(which is not function provided by MathWorks).
Please get the "load_demand" file from your colleague's system or write implementation your function.
Example:
function demand = load_demand(fileName, startDate, endDate)
excelOutput = readtable(fileName);
query = isbetween(excelOutput{:,1}, startDate, endDate);
demand = excelOutput(query,:);
end
  1 Kommentar
Walter Roberson
Walter Roberson am 22 Feb. 2021
According to other posts by the same user, the file turns out to have a date column and an hours column, but the hours problem had text such as '00-01' and '07-08'

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by