How to read multiple values in the same sheet without xlsread

For a project i have to read multiple values in a excel sheet but if i use the function xlsread it take a very long time. I try some example of program with ActiveX but it doesn't work . This is an example of my program
%1.1 : Solar Panel
nbp = xlsread('Input.xls', 'Value', 'K12'); %- Number of panels
pe = xlsread('Input.xls','Value','K13'); %Wp/m2 Power efficency of solar panels per square meter
spp = xlsread('Input.xls','Value','K14'); %m2 Size of a photovoltaic panel
aza = xlsread('Input.xls','Value','K16'); %° Azimut angle
ia = xlsread('Input.xls','Value','K17'); %° Inclinaison angle
ape = xlsread('Input.xls','Value','K19'); %% Average PV efficiency
elt = xlsread('Input.xls','Value','K20'); %% Estimed losses due to temperature and low irradiance
ela = xlsread('Input.xls','Value','K21'); %% Estimated losses due to angular reflectance effects
ol = xlsread('Input.xls','Value','K22'); %% Other losses (cable,inverter...)
pvi = xlsread('Input.xls','Value','K24'); %- PV injection to grid behavior
pvist = xlsread('Input.xls','Value','K25'); %time Start time
pviet = xlsread('Input.xls','Value','K26'); %time End time
sh = xlsread('Input.xls','Value','K28'); %period Specification of when the scenario happens

2 个评论

"if i use the function xlsread it take a very long time"
No, just the way you are (mis-)using it takes a very long time. Much faster is to simply call xlsread once and read the entire range that you need into one array. You can then allocate this data to separate variables if you so wish.
Alternatively try using this FEX submission:
Yes, as Stephen says, you're not using xlsread efficiently. The way your code is written, each time you call xlsread you are saying* to matlab:
  • start excel
  • open the excel file
  • find the spreadsheet 'Value'
  • find the cell
  • read its value
  • close the file
  • quit excel
This is not going to be very fast.
(*: matlab has made some improvements to xlsread so it actually doesn't do that anymore, but this is the spirit).

请先登录,再进行评论。

回答(1 个)

As per the comments to the question:
panelvalues = xlsread('Input.xls', 'Value', 'K12:K28')
nbp = panelvalues(1); %row 12
pe = panelvalues(2); %row 13
spp = panelvalues(3); %row 14
aza = panelvalues(5); %row 16
ia = panelvalues(6); %row 17
%etc.

Community Treasure Hunt

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

Start Hunting!

Translated by