How do I create a function to select the right excel table and data from this table with given parameters?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
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.
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 Commento
dpb
il 21 Dic 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.
Risposte (1)
Pravin Jagtap
il 24 Dic 2019
Hello,
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
end
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:
~Pravin
0 Commenti
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!