How do I create a function to select the right excel table and data from this table with given parameters?
3 ビュー (過去 30 日間)
古いコメントを表示
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.
![Ekran Alıntısı.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/256621/Ekran%20Al%C4%B1nt%C4%B1s%C4%B1.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
![22.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/256622/22.png)
1 件のコメント
dpb
2019 年 12 月 21 日
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.
回答 (1 件)
Pravin Jagtap
2019 年 12 月 24 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!