Thread Subject: I have a question about gui

Subject: I have a question about gui

From: JJ JJ

Date: 26 Nov, 2008 17:02:02

Message: 1 of 5

Hi

I want to make a simple gravity simulation.

It's very simple.

If input weight(text field) and press add button,

object is made and drop down by gravity.


The problem is here.

When one object already dropping, I add another object,

second object doesn't move until first object reaches ground.

I think, I make function move() and

function move() returns immediately from the function call.

but, how can I exactly do that ?

I want to make many object and drop down at the same time.

Subject: I have a question about gui

From: Ryan Ollos

Date: 27 Nov, 2008 09:47:02

Message: 2 of 5

"JJ JJ" <JJham2142@gmail.com> wrote in message <ggjvea$sfi$1@fred.mathworks.com>...
> Hi
>
> I want to make a simple gravity simulation.
>
> It's very simple.
>
> If input weight(text field) and press add button,
>
> object is made and drop down by gravity.
>
>
> The problem is here.
>
> When one object already dropping, I add another object,
>
> second object doesn't move until first object reaches ground.
>
> I think, I make function move() and
>
> function move() returns immediately from the function call.
>
> but, how can I exactly do that ?
>
> I want to make many object and drop down at the same time.
>

I have done animations like this using Timer functions. I assume you have a FOR loop running in move(). There is no way to make the MATLAB function move() return before it completes.

If you use a timer object, at each execution of the callback you can have a set of conditionals that creates and destroys objects, and increments the position of objects. One option is to store the data in UserData of the Timer function, so that it is accessible and can be updated on each invokation of the callback.

Subject: I have a question about gui

From: J.J. hamin

Date: 30 Nov, 2008 09:40:20

Message: 3 of 5

"Ryan Ollos" <ryano@physiosonics.com> wrote in message <gglqam$1c0$1@fred.mathworks.com>...
> "JJ JJ" <JJham2142@gmail.com> wrote in message <ggjvea$sfi$1@fred.mathworks.com>...
> > Hi
> >
> > I want to make a simple gravity simulation.
> >
> > It's very simple.
> >
> > If input weight(text field) and press add button,
> >
> > object is made and drop down by gravity.
> >
> >
> > The problem is here.
> >
> > When one object already dropping, I add another object,
> >
> > second object doesn't move until first object reaches ground.
> >
> > I think, I make function move() and
> >
> > function move() returns immediately from the function call.
> >
> > but, how can I exactly do that ?
> >
> > I want to make many object and drop down at the same time.
> >
>
> I have done animations like this using Timer functions. I assume you have a FOR loop running in move(). There is no way to make the MATLAB function move() return before it completes.
>
> If you use a timer object, at each execution of the callback you can have a set of conditionals that creates and destroys objects, and increments the position of objects. One option is to store the data in UserData of the Timer function, so that it is accessible and can be updated on each invokation of the callback.







Very Very Thanks for your answer.

It's helpful!

but, I can't make program in a concrete way.

So, Could you sent me a example source code that was mentioned your answer?

my email is JJham2142@gmail.com

Subject: I have a question about gui

From: Ryan Ollos

Date: 30 Nov, 2008 10:47:02

Message: 4 of 5

"J.J. hamin" <JJham2142@gmail.com> wrote in message <ggtn24$44i$1@fred.mathworks.com>...
> Very Very Thanks for your answer.
>
> It's helpful!
>
> but, I can't make program in a concrete way.
>
> So, Could you sent me a example source code that was mentioned your answer?
>
> my email is JJham2142@gmail.com


function hOut = moveObjectWithTimer
% This function randomly creates 'dots' and moves them across the screen

global h

h.figure = figure;

h.axes = axes('XLim', [0 10], ...
    'YLim', [0 10]);

h.line = [];

h.timer = timer('ExecutionMode', 'fixedrate', ...
    'Period', 1, ...
    'TimerFcn', @moveObject);

start(h.timer);

hOut = h;

function moveObject(tObj, eventdata)

global h

% Move objects
for i=1:length(h.line)
    XData = get(h.line(i), 'XData');
    YData = get(h.line(i), 'YData');
    XData = XData - 1;
    YData = YData - 1;
    set(h.line(i), 'XData', XData, ...
        'YData', YData);
end

% Randomly create a new object, on average every nPeriods
nPeriods = 5;
r = randi(nPeriods, 1);
if r == 1
    hObj = createObject;
    h.line = [h.line hObj];
end

% Delete objects that have reached lhs of axes
hLineTemp = h.line;
for i=1:length(h.line)
    XData = get(h.line(i), 'XData');
    YData = get(h.line(i), 'YData');
    if XData==-1 && YData==-1
        delete(hLineTemp(i))
        hLineTemp(i)=[];
    end
end
h.line = hLineTemp;


function hObj = createObject

global h

hObj = line('Parent', h.axes, ...
    'XData', 10, ...
    'YData', 10, ...
    'Marker', 'o', ...
    'MarkerFaceColor', [0 0 0], ...
    'LineStyle', 'none');
        
% [EOF]

Subject: I have a question about gui

From: J.J. hamin

Date: 3 Dec, 2008 06:47:01

Message: 5 of 5

"Ryan Ollos" <ryano@physiosonics.com> wrote in message <ggtqv6$nbi$1@fred.mathworks.com>...
> "J.J. hamin" <JJham2142@gmail.com> wrote in message <ggtn24$44i$1@fred.mathworks.com>...
> > Very Very Thanks for your answer.
> >
> > It's helpful!
> >
> > but, I can't make program in a concrete way.
> >
> > So, Could you sent me a example source code that was mentioned your answer?
> >
> > my email is JJham2142@gmail.com
>
>
> function hOut = moveObjectWithTimer
> % This function randomly creates 'dots' and moves them across the screen
>
> global h
>
> h.figure = figure;
>
> h.axes = axes('XLim', [0 10], ...
> 'YLim', [0 10]);
>
> h.line = [];
>
> h.timer = timer('ExecutionMode', 'fixedrate', ...
> 'Period', 1, ...
> 'TimerFcn', @moveObject);
>
> start(h.timer);
>
> hOut = h;
>
> function moveObject(tObj, eventdata)
>
> global h
>
> % Move objects
> for i=1:length(h.line)
> XData = get(h.line(i), 'XData');
> YData = get(h.line(i), 'YData');
> XData = XData - 1;
> YData = YData - 1;
> set(h.line(i), 'XData', XData, ...
> 'YData', YData);
> end
>
> % Randomly create a new object, on average every nPeriods
> nPeriods = 5;
> r = randi(nPeriods, 1);
> if r == 1
> hObj = createObject;
> h.line = [h.line hObj];
> end
>
> % Delete objects that have reached lhs of axes
> hLineTemp = h.line;
> for i=1:length(h.line)
> XData = get(h.line(i), 'XData');
> YData = get(h.line(i), 'YData');
> if XData==-1 && YData==-1
> delete(hLineTemp(i))
> hLineTemp(i)=[];
> end
> end
> h.line = hLineTemp;
>
>
> function hObj = createObject
>
> global h
>
> hObj = line('Parent', h.axes, ...
> 'XData', 10, ...
> 'YData', 10, ...
> 'Marker', 'o', ...
> 'MarkerFaceColor', [0 0 0], ...
> 'LineStyle', 'none');
>
> % [EOF]



THANKS !!

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com