Multiple instances of spreadsheet-populated uitree in App Designer

4 ビュー (過去 30 日間)
Isaac Blanc
Isaac Blanc 2022 年 9 月 23 日
回答済み: Tushar 2023 年 8 月 31 日
Background
I have programmed an app that reads data from an Excel spreadsheet into a table* and uses it to populate a uitree. It is very similar to this App Designer example, except that the user can add their own items. When this happens, the app writes the new item to the Excel spreadsheet, then re-reads the spreadsheet into the table and then re-populates the uitree with the new data in the table. Its certainly not the most efficient way of doing things, but its simple and runs fast enough.
I've written several functions to pass data between the spreadsheet, the table and the uitree so that everything stays 'in sync'. The main ones are:
  • Reading the Excel spreadsheet to a table
  • Populating the uitree from the table, including creating category nodes
  • Writing a new item to the spreadsheet
  • Refreshing the table & uitree after writing to spreadsheet
Question
I now want to program a new app that contains several different uitrees, each of which is linked to a different spreadsheet. What is the best way to do this in order to keep things neat and open to future development?
I think the best way is to define a custom class, with properties:
  • Spreadsheet filename
  • Table
  • uitree
And methods being the functions listed above. Then I could create an instance of this class each time I wanted to have a new spreadsheet-populated uitree in my app. It would keep things neat, since the data and functions for each uitree would be contained in each class instance. I could then also create as many spreadsheet-populated uitrees as I want without having to write new functions each time.
As you can tell, I'm pretty new to object oriented programming. Do you think this is a good plan?
*by 'table', I mean the Matlab data type, not the UI component uitable

回答 (1 件)

Tushar
Tushar 2023 年 8 月 31 日
Hi Isaac,
I understand that you are looking for a way to program an app that populates a 'uitree' using a spreadsheet. This needs to be done for multiple 'uitrees' with their respective spreadsheets. I'd like to suggest two workflows that can be used for this:
  • User-friendly Workflow: In this workflow, you can read the spreadsheet into a table and populate the 'uitree' based on the table data. You can refresh the 'uitree' whenever the spreadsheet is updated with new items. This approach is user-friendly as it doesn't require writing additional code for new items. You can define a custom class with the necessary properties mentioned above, which would work perfectly for this purpose.
  • Efficient Workflow: Alternatively, you can provide users with an editable section of the code for each instance of the custom class. You can also share documentation on how to add new items to the 'uitree' independently. This workflow assumes that you don't want the spreadsheet to be automatically updated with the new items. If you do require the spreadsheet to be updated, we would need to consider a different approach.
I hope these suggestions help you with your query. In addition to the workflows mentioned above, the resources and documentations shared in your question should provide you with adequate guidance to implement the desired functionality. For more information about OOPS, you can check out "Object-Oriented Programming in MATLAB" and navigate your way through.

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by