MATLAB Gui, text-box value on buttonpress without GUIDE





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a certain GUI built without GUIDE, just plain old uicontrols and I've gotten everything to work properly so far. However I want to, upon a button press grab the value in a text-box (edit) and store it into a variable fi.



Basically the code in question;



c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation','Callback', 
@rotation);
s1 = uicontrol(f,'Style', 'edit');

function rotation(src,event)
load 'BatMan.mat' X
fi = %This is the value I want to have the value as the edit box.
subplot(2,2,1)
PlotFigure(X)
end









share|improve this question





























    1















    I have a certain GUI built without GUIDE, just plain old uicontrols and I've gotten everything to work properly so far. However I want to, upon a button press grab the value in a text-box (edit) and store it into a variable fi.



    Basically the code in question;



    c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation','Callback', 
    @rotation);
    s1 = uicontrol(f,'Style', 'edit');

    function rotation(src,event)
    load 'BatMan.mat' X
    fi = %This is the value I want to have the value as the edit box.
    subplot(2,2,1)
    PlotFigure(X)
    end









    share|improve this question

























      1












      1








      1








      I have a certain GUI built without GUIDE, just plain old uicontrols and I've gotten everything to work properly so far. However I want to, upon a button press grab the value in a text-box (edit) and store it into a variable fi.



      Basically the code in question;



      c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation','Callback', 
      @rotation);
      s1 = uicontrol(f,'Style', 'edit');

      function rotation(src,event)
      load 'BatMan.mat' X
      fi = %This is the value I want to have the value as the edit box.
      subplot(2,2,1)
      PlotFigure(X)
      end









      share|improve this question














      I have a certain GUI built without GUIDE, just plain old uicontrols and I've gotten everything to work properly so far. However I want to, upon a button press grab the value in a text-box (edit) and store it into a variable fi.



      Basically the code in question;



      c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation','Callback', 
      @rotation);
      s1 = uicontrol(f,'Style', 'edit');

      function rotation(src,event)
      load 'BatMan.mat' X
      fi = %This is the value I want to have the value as the edit box.
      subplot(2,2,1)
      PlotFigure(X)
      end






      matlab matlab-gui






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 23:30









      Anton HagelbergAnton Hagelberg

      83




      83
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Easiest is to get rotation to know about s1 through an input argument:



          c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation');
          s1 = uicontrol(f,'Style', 'edit');
          set(c2,'Callback',@(src,event)rotation(s1,src,event));

          function rotation(s1,src,event)
          load 'BatMan.mat' X
          fi = get(s1,'String');
          subplot(2,2,1)
          PlotFigure(X)
          end


          Here, we set the callback for c2 to be an anonymous function with the right signature (2 input arguments), and which calls rotation with s1 as an additional argument. The callback now has the handle s1 embedded in it.






          share|improve this answer
























          • Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

            – Anton Hagelberg
            Nov 17 '18 at 0:13













          • @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

            – Cris Luengo
            Nov 17 '18 at 0:15











          • Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

            – Anton Hagelberg
            Nov 17 '18 at 0:20












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346700%2fmatlab-gui-text-box-value-on-buttonpress-without-guide%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Easiest is to get rotation to know about s1 through an input argument:



          c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation');
          s1 = uicontrol(f,'Style', 'edit');
          set(c2,'Callback',@(src,event)rotation(s1,src,event));

          function rotation(s1,src,event)
          load 'BatMan.mat' X
          fi = get(s1,'String');
          subplot(2,2,1)
          PlotFigure(X)
          end


          Here, we set the callback for c2 to be an anonymous function with the right signature (2 input arguments), and which calls rotation with s1 as an additional argument. The callback now has the handle s1 embedded in it.






          share|improve this answer
























          • Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

            – Anton Hagelberg
            Nov 17 '18 at 0:13













          • @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

            – Cris Luengo
            Nov 17 '18 at 0:15











          • Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

            – Anton Hagelberg
            Nov 17 '18 at 0:20
















          1














          Easiest is to get rotation to know about s1 through an input argument:



          c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation');
          s1 = uicontrol(f,'Style', 'edit');
          set(c2,'Callback',@(src,event)rotation(s1,src,event));

          function rotation(s1,src,event)
          load 'BatMan.mat' X
          fi = get(s1,'String');
          subplot(2,2,1)
          PlotFigure(X)
          end


          Here, we set the callback for c2 to be an anonymous function with the right signature (2 input arguments), and which calls rotation with s1 as an additional argument. The callback now has the handle s1 embedded in it.






          share|improve this answer
























          • Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

            – Anton Hagelberg
            Nov 17 '18 at 0:13













          • @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

            – Cris Luengo
            Nov 17 '18 at 0:15











          • Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

            – Anton Hagelberg
            Nov 17 '18 at 0:20














          1












          1








          1







          Easiest is to get rotation to know about s1 through an input argument:



          c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation');
          s1 = uicontrol(f,'Style', 'edit');
          set(c2,'Callback',@(src,event)rotation(s1,src,event));

          function rotation(s1,src,event)
          load 'BatMan.mat' X
          fi = get(s1,'String');
          subplot(2,2,1)
          PlotFigure(X)
          end


          Here, we set the callback for c2 to be an anonymous function with the right signature (2 input arguments), and which calls rotation with s1 as an additional argument. The callback now has the handle s1 embedded in it.






          share|improve this answer













          Easiest is to get rotation to know about s1 through an input argument:



          c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation');
          s1 = uicontrol(f,'Style', 'edit');
          set(c2,'Callback',@(src,event)rotation(s1,src,event));

          function rotation(s1,src,event)
          load 'BatMan.mat' X
          fi = get(s1,'String');
          subplot(2,2,1)
          PlotFigure(X)
          end


          Here, we set the callback for c2 to be an anonymous function with the right signature (2 input arguments), and which calls rotation with s1 as an additional argument. The callback now has the handle s1 embedded in it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 17 '18 at 0:03









          Cris LuengoCris Luengo

          23.2k52254




          23.2k52254













          • Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

            – Anton Hagelberg
            Nov 17 '18 at 0:13













          • @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

            – Cris Luengo
            Nov 17 '18 at 0:15











          • Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

            – Anton Hagelberg
            Nov 17 '18 at 0:20



















          • Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

            – Anton Hagelberg
            Nov 17 '18 at 0:13













          • @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

            – Cris Luengo
            Nov 17 '18 at 0:15











          • Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

            – Anton Hagelberg
            Nov 17 '18 at 0:20

















          Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

          – Anton Hagelberg
          Nov 17 '18 at 0:13







          Thank you for your comment, however I'm getting an error using the get method; Cannot find 'get' method for matlab.ui.eventdata.ActionData class.

          – Anton Hagelberg
          Nov 17 '18 at 0:13















          @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

          – Cris Luengo
          Nov 17 '18 at 0:15





          @AntonHagelberg: That means that you still have @rotation as a callback function somewhere. Make sure you set the callback as I show here.

          – Cris Luengo
          Nov 17 '18 at 0:15













          Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

          – Anton Hagelberg
          Nov 17 '18 at 0:20





          Can't thank you enough! I found this se.mathworks.com/matlabcentral/answers/… and started trying to rebuild my entire GUI in this fashion instead but quickly realized it was a rough bit. This fixed my issues completely and I feel like I got a better understanding for using uicontrols in matlab :)

          – Anton Hagelberg
          Nov 17 '18 at 0:20




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346700%2fmatlab-gui-text-box-value-on-buttonpress-without-guide%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine