Wednesday, June 27, 2012

Sharing data among MATLAB GUIs: Part 3

In this post, I am going to share some of my principles in designing the data sharing among GUIs and use an example in the comment left by Anonymous to demonstrate how they work. 

The design procedure is fairly straightforward, simply following the four steps below should give you a clear picture as to how the data is communicated among all the GUIs in the application. 

1. Draw out all the GUIs. 
2. Connect the GUIs that will share data.
3. Determine the flow of the data for each connection.
4. Determine the possible action (push and/or pull) associated with the flow of data. 


Let's try it with the sample problem below:

I am working on 3 GUIs (using GUIDE). GUI-1 will call GUI-2 (used to collect user inputs, process the input data) and then output the results to GUI-3. 

Based on the description of the problem, the diagram in Figure 1 depicts the process of the design. Step 1 involves drawing there blocks for GUI-1, GUI-2, and GUI-3. Since it is stated that GUI-1 will call GUI-2 and then outputs the results to GUI-3, so connections are drawn between GUI-1 and GUI-2, GUI-1 and GUI-3. For the same reason, the flow of the data can be easily determined as from GUI-2 to GUI-1, and from GUI-1 to GUI-3. In Step 4, since it was stated that GUI-1 will call GUI-2, so I assign the pull action to the flow of data from GUI-2 to GUI-1, and since the data is processed by GUI-1 and output to GUI-3, I assign a push action to the flow of data from GUI-1 to GUI-3. 

Figure 1. A sample design process
In the next post, we will look at how to implement the data sharing based on the design. 

7 comments:

  1. Wei, I think I did NOT make myself clear enough:
    GUI-1 (main, will open first) has a pushbutton whose callback opens GUI-2. GUI-2 has several edittexts (let's say, 4) that will provide user inputs. The inputs will be used to do various calculations and then the results (let's also say about 4 of them) will be displayed in textboxes in GUI-3. I hope this clarifies the problem. Thank you.

    ReplyDelete
  2. Hello.

    You have explained very clearly as to what each of the GUI does. What I need you to do next is walk me through the expected user interactions. Specifically, after GUI-1 opens GUI-2, and the user inputs all the data, what does the user need to do to have the data sent over to GUI-1. Is there a 'send data' button on GUI-2 that the user can click on? Or is there a 'acquire data' button on GUI-1?

    Also, does GUI-2 stay open all these time? or is it more like a 'pop-up' GUI that opens and closes all the time?

    Finally, for GUI-3, does the user need to do anything to have the results display on GUI-3? or are the results displayed in GUI-3 once the data are accepted by GUI-1?

    Sorry for all the questions, but I want to make sure you can get the most out of the next few posts.

    ReplyDelete
  3. Wei, thanks again for your help. GUI-1 is supposed to be the main GUI that will serve as a gateway to start the program/model. It will have a fancy description about what the program/model is. It has a pushbutton which if clicked opens GUI-2. Once it opens GUI-2, GUI-1's work would have been done. GUI-2 then becomes where the modeling input data and processing will start. It will allow users to input data to the model. The input data from users will then be used to perform certain calculations. Let's say I have developed a class object (using object oriented programming, OOP) that need to be initiated with data. The input data will be used to create an instance of a class object. The methods of the class object will then become the results of the model. These results are supposed to be sent to GUI-3, which then become the final output display for the modeling. While GUI-1 will close after starting the modeling, GUI-2 and GUI-3 will still be opened, so that when the input data in GUI-2 are changed, the new/changed results in GUI-3 can also be seen. GUI-1 will have a pushbutton which when clicked opens GUI-2 and closes GUI-1. GUI-2 will have (in addition to the 4 edit texts) a pushbutton which when clicked will open GUI-3. GUI-3 displays the 4 final model results in 4 text boxes. GUI-3 will also have a pushbutton which when clicked then closes all the remaining GUIs i.e. GUI-2 and GUI-3. Thanks a lot.

    ReplyDelete
  4. Thanks for all the detail. I think I know what you are trying to do.

    I promise you this is my final question. :)

    Would you like me to start from scratch and go through all the details, e.g., click button on GUI-1 to open GUI-2, ..., click button on GUI-3 to close all GUIs, etc, or are you just interested in knowing how you can get GUI-2 to send the data to GUI-3?

    ReplyDelete
  5. Wei, I appreciate your help very much. I will be just okay with the communication portion alone, but for the sake of someone new to MATLAB who might NOT understand the entire concept very much, please, go through the entire exercise.

    Thank you very much.

    ReplyDelete
  6. Alright. I probably need a couple days to think about how to write this. Please bear with me. :)

    ReplyDelete
  7. Sorry for the long delay. I used your example and showed a quick and easy way to get things done (link below).

    http://we15hang.blogspot.ca/2012/07/example.html

    Let me know if anything is not clearly explained or somehow the example is different from what you have in mind.

    Good luck.

    ReplyDelete