using self created class in gui

2 views (last 30 days)
jeff wu
jeff wu on 9 Mar 2012
hi, im trying to understand the the oop concept in matlab. i got some classes
classdef myclass
...
end
without gui i could write
blabla = myclass
but i want to create an instance of a class when a button is clicked. so in that case i dont have a name for that instance or object. how is that generally done in matlab
thanx a lot

Answers (2)

Sean de Wolski
Sean de Wolski on 9 Mar 2012
Well, what do you want to name it? And what do you want to do with it after? You could have an edit box in the gui qwhere the user puts in the name they want to call it. etc. This is a hard question to answer without more detail.
  1 Comment
jeff wu
jeff wu on 9 Mar 2012
hi, thanks for ur answer
i wanna use it for structural analizes on beams. so i have at least one beam with several properties like Material, length, width, height...
on another hand i let the user enter the diferent forces inside the beams and i perform different calculations on it in order to determine if the beam is able to take thees forces without craching or deforming to much. without gui i would type " slab1 = myclass" and perform the different calculations with this class. the point is i wanna keep this calculated information, so if the user has several slabs to calculate it would be easy to create a new instance of that class and do the calculations in the same way. " slab2 = myclass"... will not work since every myclassObhject shoul be adde d by pushing button and there is no name. or shal i generate a name like mystr= Slab. the name of the instanced would then be mystr+number. and number keeps track how many instances there are. this seems a bit basic and i cant imagine that there isnt another way for doing it.
i hope i got it a bit clearer. thanks again

Sign in to comment.


Walter Roberson
Walter Roberson on 9 Mar 2012
You would still write
blabla = myclass
in your callback of the button. That will create the instance within the workspace of the callback function.
The problem then shifts to how you avoid having the instance destroyed when the callback function returns. The answers to that are much like if it was a numeric value you had computed: store the object somewhere that will continue to exist once the callback function returns.

Categories

Find more on Data Type Identification 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!