Error with reading excel file

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 comentarios

Walter Roberson
Walter Roberson el 19 de Feb. de 2021
load_demand does not appear to be a Mathworks function (unless it happens to be in one of the examples somewhere)
Anders Vigen
Anders Vigen el 19 de Feb. de 2021
Editada: Anders Vigen el 19 de Feb. de 2021
@Walter RobersonOkay so if it's not a Mathworks function (even though seems weird since it works on my colleagues computer), how would I fix this problem, I would obviously need to use a different function?
Have one of them query
which load_demand
and see what shows up.
Anders Vigen
Anders Vigen el 19 de Feb. de 2021
@Walter Roberson unfortunately it says the same thing.
Walter Roberson
Walter Roberson el 19 de Feb. de 2021
What was the output on both systems?
Anders Vigen
Anders Vigen el 20 de Feb. de 2021
@Walter Roberson I'm not sure what you mean by output. But the purpose of the script was to plot the load demand for a specific day, from an excel sheet containing the load demand for very day for a year.
which load_demand
When you executed that command on your colleague's system what was the output?
Anders Vigen
Anders Vigen el 20 de Feb. de 2021
I obtained the below plot.
If you obtained a plot when you gave that command, then you have accidentally overwritten the important MATLAB command "which".
>> which load_demand
'load_demand' not found.
>> which timerange
/Applications/MATLAB_R2020b.app/toolbox/matlab/datatypes/tabular/timerange.m % timerange constructor
That's the sort of output you should have seen when you ran the command
which load_demand
on your colleague's computer: either "not found" or the location of the implementing method.
Anders Vigen
Anders Vigen el 20 de Feb. de 2021
@Walter Roberson this might be a stupid question, but if I did accidentally overwrite the which command, how do I fix that?
What shows up if you give the command
builtin('which', 'which')
built-in (/MATLAB/toolbox/matlab/general/which)
Anders Vigen
Anders Vigen el 20 de Feb. de 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);
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

Iniciar sesión para comentar.

Más respuestas (1)

Ani Singh
Ani Singh el 21 de Feb. de 2021

0 votos

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 comentario

Walter Roberson
Walter Roberson el 22 de Feb. de 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'

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 19 de Feb. de 2021

Respondida:

el 23 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by