How to Link MATLAB GUI User Inputs to a Simulation Equation?

Click For Summary

Discussion Overview

The discussion revolves around creating a MATLAB GUI for simulating simple harmonic motion of a spring-mass system. Participants seek assistance in linking user inputs to simulation equations and handling graphical representations of the motion.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes their project involving a GUI for modeling simple harmonic motion and requests help in connecting user inputs to the governing equation.
  • Another participant expresses difficulty in creating a GUI for a linear equation and seeks guidance on editing callback functions.
  • There are suggestions to use the 'GUIDE' command in MATLAB and to look for examples of existing GUIs for reference.
  • One participant mentions that most callbacks may not need to be filled out entirely and suggests placing the main simulation code within the callback of a button.
  • Another participant inquires about the graphical representation of the mass-spring system and requests clarification on how the "live" graph was created.

Areas of Agreement / Disagreement

Participants express various levels of understanding and experience with MATLAB GUIs, leading to differing opinions on the best approach to implement the simulation and graphical elements. No consensus is reached on specific methods or solutions.

Contextual Notes

Some participants mention challenges with callback functions and graphical representations, indicating potential gaps in knowledge or experience with MATLAB's GUI capabilities.

Who May Find This Useful

Individuals interested in MATLAB programming, GUI development, and simulations of physical systems may find this discussion relevant.

ranger
Gold Member
Messages
1,687
Reaction score
2
[Matlab virgin here]

I am in great need of some help. My task is to create GUI app to model simple harmonic motion of a spring with a mass attached to it. The requirements are to have the user be able to change every parameter of the equation:
my'' + cy' + ky' = f(t)

The m, c, k, and f are the usual constants - mass, spring constant and so on. Upon changing these parameters the user should be able to see a live visual of the spring moving and a graph for an analytical understanding of the motion through some specified time of action. By default the time of action should be about 10sec then the simulation stops and the parameters could be changed.

This is what I've done so far:
Made the complete GUI app. This includes all necessary user interfacing, the "live" graph, and spring animation.

Now what I need some help on is the relate all the user inputs to the formula to get the simulation.
Yea, I know I haven't done much because the GUI was the easy part, but I did get the "grid on" and "grid off" buttons to work:biggrin: Other than that, I pretty much didnt do any Callbacks and so on to help analyze the data.

Can someone help me get started?

http://linuxfreak87.googlepages.com/HarmonicSpring.m <-- m-file
http://linuxfreak87.googlepages.com/HarmonicSpring.fig <--fig file

Using Matlab 7 R14

--thank you.
 
Last edited:
Physics news on Phys.org
hi group community
i am getting it dificult to create GUI for solving equations for y=mx+c;
i have failed to edit m file but if completed to create the figure
can someone hel;p me to intiate and edit the call back function
thanks
 
mussaco said:
hi group community
i am getting it dificult to create GUI for solving equations for y=mx+c;
i have failed to edit m file but if completed to create the figure
can someone hel;p me to intiate and edit the call back function
thanks

try 'GUIDE' command in Matlab. Then look on Matlab's website for information on how to operate guide and perhaps seek examples of other working GUI's. Other than that, maybe wait to make your own thread since ranger needs his own help here! Still, welcome to the forums, mussaco.

And ranger, whilst this may have been an old post - I don't have more free time at the moment than required to make a simple post (i.e. this :smile:) but I will try to have a look at your files and let you know of the results. I would also suggest looking for an example GUI in the meantime if it's really bugging you. Are you still working on the problem?
 
i am still working on the problem
but does the equation y=mx+c apperas on the opening function or on the callback function to make the gui calculate?
regards
mussa
 
ranger said:
[Matlab virgin here]

I am in great need of some help. My task is to create GUI app to model simple harmonic motion of a spring with a mass attached to it. The requirements are to have the user be able to change every parameter of the equation:
my'' + cy' + ky' = f(t)

The m, c, k, and f are the usual constants - mass, spring constant and so on. Upon changing these parameters the user should be able to see a live visual of the spring moving and a graph for an analytical understanding of the motion through some specified time of action. By default the time of action should be about 10sec then the simulation stops and the parameters could be changed.

This is what I've done so far:
Made the complete GUI app. This includes all necessary user interfacing, the "live" graph, and spring animation.

Now what I need some help on is the relate all the user inputs to the formula to get the simulation.
Yea, I know I haven't done much because the GUI was the easy part, but I did get the "grid on" and "grid off" buttons to work:biggrin: Other than that, I pretty much didnt do any Callbacks and so on to help analyze the data.

Can someone help me get started?

http://linuxfreak87.googlepages.com/HarmonicSpring.m <-- m-file
http://linuxfreak87.googlepages.com/HarmonicSpring.fig <--fig file

Using Matlab 7 R14

--thank you.

hi dear I'm now working on the same project as you done it
and have thesame problem as you had.
can you mail me on s.hosseini1365@gmail.com to how can i do it!
tanks a lot.
 
You don't need to fill most of the callbacks. I've made several GUI's and if your code isn't amazingly complicated then you can just put the entire code inside the callback of your "Start Simulation" button or whatever you've called it.

I've never made a realtime simulation like you're trying to do now but i think the standard MATLAB way of doing such a thing is by setting your main function inside of a loop and adding a very small pause at the end.
 
Hi

I am facing trouble with the graphics in the GUI, I am trying to do something similar but i donwload your files and can't find where did you "draw" the mass-spring sistem, please could you tell me how did you draw that "live" graph
 
Last edited:

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
4K