How can I use a a text file as a source for your popup menu in guide (i.e. items in the list)

2 views (last 30 days)
I am trying to make a database system to store information into specified profiles. I have been successful in setting up the structure for the profiles, but however the number of profiles keep on updating per usage. I have managed to to write a .m file to write all names of profiles into a .txt file. I simply need a solution upon how I can link this .txt file to my drop down menu in guide.
  2 Comments
Jan
Jan on 22 Apr 2014
Edited: Jan on 22 Apr 2014
Why do you write the names to a txt file at first? Is this indirection useful? Does the list change its contents during the GUI is open? What did you try already and which problems are you working on?
Kwaku Amanfro
Kwaku Amanfro on 25 Apr 2014
They are profiles created and stored in a struct file. Because the popupmenu only accepts strings, the best solution I could find was to write it all into a text file using fopen/fclose and link the popup menu to the text file. {Therefore anytime the m. file is opened, the text file is rewritten.}. Kindly assist me if there is a better way...Thanks

Sign in to comment.

Accepted Answer

Joseph Cheng
Joseph Cheng on 22 Apr 2014
however you have the popup menu updated, read in the text file with each entry as a cell(M profiles in one column). Then you can update the popup menu with
set(handles.popupmenu1,'String',profileNamesReadfromTXT)
  2 Comments
Kwaku Amanfro
Kwaku Amanfro on 25 Apr 2014
run Text_Writer_Oil A = importdata('popup_menu_oil.txt'); set(hObject,'String',A);
That is the code and is now working perfectly (popup menu)
The text writer code is as shown below (this is the part that does the writing)
fid = fopen('popup_menu_oil.txt','w'); for s = 1: sum(a.id(:,1)~=0) if new.field_name{s,1} ~= '''' c = new.field_name{s,1}; fprintf(fid,'%s\n',c); end end fclose(fid);
I had to do a little sorting before finally writing the above stated

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!