Search code examples
matlabuser-interfaceworkspace

Drop Down GUI matlab


 function DoneButtonPushed(app, event)
            assignin('base','roll_no_GUI1',app.StudentInfoDropDown.Value);
            assignin('base','projname_GUI1',app.ProjectInfoDropDown.Value);
            assignin('base','roll_no_GUI2',app.StudentInfoDropDown_2.Value);
            assignin('base','projname_GUI2',app.ProjectInfoDropDown_2.Value);
            assignin('base','roll_no_GUI3',app.StudentInfoDropDown_3.Value);
            assignin('base','projname_GUI3',app.ProjectInfoDropDown_3.Value);
            assignin('base','roll_no_GUI4',app.StudentInfoDropDown_4.Value);
            assignin('base','projname_GUI4',app.ProjectInfoDropDown_4.Value);
            assignin('base','roll_no_GUI5',app.StudentInfoDropDown_5.Value);
            assignin('base','projname_GUI5',app.ProjectInfoDropDown_5.Value);
            closereq
        end

Hi, I am creating a GUI which contains DropDowns. They are 10 dropdowns as you can see from the code. And I am using assignin to save each one of them into base workspace. But I would like to club all of them into a 2 char array's or 2 cell array's and send only two variables into the base workspace viz, Roll_nos and Projnames_GUI


Solution

  • Create two cell arrays and assign them in the base workspace:

    roll_nos = {
      app.StudentInfoDropDown.Value,
      app.StudentInfoDropDown_2.Value,
      app.StudentInfoDropDown_3.Value,
      app.StudentInfoDropDown_4.Value,
      app.StudentInfoDropDown_5.Value
    };
    
    projnames_gui = {
      app.ProjectInfoDropDown.Value,
      app.ProjectInfoDropDown_2.Value,
      app.ProjectInfoDropDown_3.Value,
      app.ProjectInfoDropDown_4.Value,
      app.ProjectInfoDropDown_5.Value
    };
    
    assignin('base','Roll_nos',roll_nos)
    assignin('base','Projnames_GUI',projnames_gui)