How do I create a function to select the right excel table and data from this table with given parameters?

5 visualizaciones (últimos 30 días)
The code I will write should first select the correct table from 10 excel tables using the 2 parameters I entered, then select the data I need in that table using the other 2 parameters entered. I want to write these operations as a function. I would appreciate it if you could tell me how to write this function.
For example, there are 10 tables on 10 different pages in this excel file. The code will control 2 parameters to select the correct one from the tables. One will be a diameter value and one will be a ratio value.
Ekran Alıntısı.PNG
When I select the table, I will give two parameters as input. For example;
pass = input ('Desired Pass =');
Desired Pass = 2_P
Ds = input ('Enter Shell Diameter (Ds):');
Enter Shell Diameter (Ds): 0.2032
  1 comentario
dpb el 21 de Dic. de 2019
So, have you put anything into the sheet names to be able to read to know which sheet contains the desired information? Or can you compute that sheet number knowing the structure of the data within the workbook?
If not, you'll have to read each sheet and do a search for the parameters you're looking for.
Unless the spreadsheets are very large, it probaby makes more sense to just pull all the data into memory and search within it---turning it into a MATLAB table instead of spreadsheet and saving that as a .mat file for future use would likely save a lot of coding otherwise.
W/o an actual copy of the spreadsheet, not much else anyone here can do...we don't have the particulars to write specific code.

Iniciar sesión para comentar.

Respuestas (1)

Pravin Jagtap
Pravin Jagtap el 24 de Dic. de 2019
Refer following code to load the data in MATLAB workspace:
[~,sheet_name]=xlsfinfo('Book1.xlsx'); % 'Book1.xlsx' is the workbook
data = cell(2); % Declared the cell array of size two for demo
for k=1:numel(sheet_name)
data{k}=xlsread('Book1.xlsx',sheet_name{k}); % data{1}, data{2} represents the sheet1 and sheet2
After loading the data, you can process it based on your requirements using your parameters. As mentioned in the above comment you need to consider search space depending on data size. This is just a possible workaround.
You can also refer to the following documentation (of 'readmatrix') for achieving your objectives which offers more functionality:

Community Treasure Hunt

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

Start Hunting!

Translated by