Updating Listbox / Files / Case-Switch Based on User Input

1 回表示 (過去 30 日間)
Jonathan
Jonathan 2012 年 7 月 25 日
Hey guys, thanks in advance for any responses. I've been working on a series of GUIs that allow the user to control a stepper motor as a function of another motor's RPM and have had quite a bit of success. The current functionality I'm trying to add to the software is the ability for the user to define their own function of control, which would create a file with a name they've chosen, add a string to the listbox with the description they've chosen, and add the functionality to the code. I've run into an error in this bit because I can't seem to think of the best way to do it, I've thought about storing all the data in cells and referencing them, or writing them to a file, or trying to use structs, but I could really use some input. I'll attach some code for a better description below.
User hits "add new function" button which calls the first in a series of 4 GUIs that define fileName, functionName, functionActual, and creates the file corresponding to their function (in a sub folder) using getappdata/setappdata to transfer data between GUIs.
The main GUI has to see which function they've selected after a toggle button is pushed and call that specific file for an feval() code, which I've been doing like this ('Normal0F' is the file name):
switch get(handles.functionChoice,'Value')
case 1
functionCall = 'Normal0F';
case 2
functionCall = 'Lateral0F';
case 3
functionCall = 'Normal5A';
end
So this code needs to update with another case that corresponds to the next value. I thought about using functionList = what(<subfolder dir>); functionList.m to make some sort of array containing the file names, but the function call names (listbox) have to correspond to the right file names which the OS may send back in ABC order, or date modified, depending on how the folder is set up.
THANKS A MILLION! Looking forward to your input.
  1 件のコメント
Jonathan
Jonathan 2012 年 7 月 26 日
I'm surprised someone hasn't piped up about this, doesn't seem too difficult!

サインインしてコメントする。

採用された回答

Jonathan
Jonathan 2012 年 7 月 27 日
Well, since no one had answered this question yet I went with a very inelegant solution.
Let the listbox (popupmenu) be populated by a text file with the list of the funcions, outsource the functionCall switch/case function to another .m file, then just write the updated information into the files as needed (which is the really inelegant part, copy the file line by line until the "end", add the new lines of code, replace end).
It works, I guess I can't complain!
If you have a better solution, I would still love to hear it!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by