Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
GUI to exe problem

Subject: GUI to exe problem

From: Jan

Date: 15 Mar, 2013 18:07:11

Message: 1 of 7

Hi,
I have problem with exe file functionality. I guess it is because of "evalin('base', mfilename)". So I need to find a way how to evaluate scripts in caller workspace. Problem is, that caller workspace do not know variables i already loaded in .mat file

load wtr.mat;
if PR(i,j)>=Pmin;
    PR(i,j)=PR(i,j);
else PR(i,j)=0;

Pmin and PR were loaded by wtr.mat
Thanks for any suggestions
Jan

Subject: GUI to exe problem

From: Kristin

Date: 19 Mar, 2013 23:00:25

Message: 2 of 7

"Jan " <urbanecjan@gmail.com> wrote in message <khvo0e$o8n$1@newscl01ah.mathworks.com>...
> Hi,
> I have problem with exe file functionality. I guess it is because of "evalin('base', mfilename)". So I need to find a way how to evaluate scripts in caller workspace. Problem is, that caller workspace do not know variables i already loaded in .mat file
>
> load wtr.mat;
> if PR(i,j)>=Pmin;
> PR(i,j)=PR(i,j);
> else PR(i,j)=0;
>
> Pmin and PR were loaded by wtr.mat
> Thanks for any suggestions
> Jan

I'm a little confused on what you're trying to do. Why do you need to use evalin at the base workspace, as opposed to calling a function and passing variables?

Subject: GUI to exe problem

From: Jan

Date: 21 Mar, 2013 12:16:06

Message: 3 of 7

"Kristin" wrote in message <kiaqm9$t0a$1@newscl01ah.mathworks.com>...
> "Jan " <urbanecjan@gmail.com> wrote in message <khvo0e$o8n$1@newscl01ah.mathworks.com>...
> > Hi,
> > I have problem with exe file functionality. I guess it is because of "evalin('base', mfilename)". So I need to find a way how to evaluate scripts in caller workspace. Problem is, that caller workspace do not know variables i already loaded in .mat file
> >
> > load wtr.mat;
> > if PR(i,j)>=Pmin;
> > PR(i,j)=PR(i,j);
> > else PR(i,j)=0;
> >
> > Pmin and PR were loaded by wtr.mat
> > Thanks for any suggestions
> > Jan
>
> I'm a little confused on what you're trying to do. Why do you need to use evalin at the base workspace, as opposed to calling a function and passing variables?

Main problem is, that for my simulation I need to load data with variables which are processed later. I used load 'filename', uigetfile, ... and other conventional ways to load them but error message with unknown variable is still showing up.

Subject: GUI to exe problem

From: Steven_Lord

Date: 21 Mar, 2013 13:25:31

Message: 4 of 7



"Jan " <urbanecjan@gmail.com> wrote in message
news:kietm5$9ii$1@newscl01ah.mathworks.com...
> "Kristin" wrote in message <kiaqm9$t0a$1@newscl01ah.mathworks.com>...
>> "Jan " <urbanecjan@gmail.com> wrote in message
>> <khvo0e$o8n$1@newscl01ah.mathworks.com>...
>> > Hi, I have problem with exe file functionality. I guess it is because
>> > of "evalin('base', mfilename)". So I need to find a way how to evaluate
>> > scripts in caller workspace. Problem is, that caller workspace do not
>> > know variables i already loaded in .mat file
>> >
>> > load wtr.mat;
>> > if PR(i,j)>=Pmin;
>> > PR(i,j)=PR(i,j);
>> > else PR(i,j)=0;
>> >
>> > Pmin and PR were loaded by wtr.mat
>> > Thanks for any suggestions Jan
>>
>> I'm a little confused on what you're trying to do. Why do you need to use
>> evalin at the base workspace, as opposed to calling a function and
>> passing variables?
>
> Main problem is, that for my simulation I need to load data with variables
> which are processed later. I used load 'filename', uigetfile, ... and
> other conventional ways to load them but error message with unknown
> variable is still showing up.

Inside a function you should ALWAYS call LOAD in its function form with an
output argument.

data = load('wtr.mat');
if data.x < 5
    % do something
end

If you need to refer to the x variable from wtr.mat using the name x, not
the expression data.x, use:

x = data.x;

in your function after loading the data.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: GUI to exe problem

From: Jan

Date: 21 Mar, 2013 20:32:25

Message: 5 of 7

"Steven_Lord" <slord@mathworks.com> wrote in message <kif1ob$mo6$1@newscl01ah.mathworks.com>...
>
>
> "Jan " <urbanecjan@gmail.com> wrote in message
> news:kietm5$9ii$1@newscl01ah.mathworks.com...
> > "Kristin" wrote in message <kiaqm9$t0a$1@newscl01ah.mathworks.com>...
> >> "Jan " <urbanecjan@gmail.com> wrote in message
> >> <khvo0e$o8n$1@newscl01ah.mathworks.com>...
> >> > Hi, I have problem with exe file functionality. I guess it is because
> >> > of "evalin('base', mfilename)". So I need to find a way how to evaluate
> >> > scripts in caller workspace. Problem is, that caller workspace do not
> >> > know variables i already loaded in .mat file
> >> >
> >> > load wtr.mat;
> >> > if PR(i,j)>=Pmin;
> >> > PR(i,j)=PR(i,j);
> >> > else PR(i,j)=0;
> >> >
> >> > Pmin and PR were loaded by wtr.mat
> >> > Thanks for any suggestions Jan
> >>
> >> I'm a little confused on what you're trying to do. Why do you need to use
> >> evalin at the base workspace, as opposed to calling a function and
> >> passing variables?
> >
> > Main problem is, that for my simulation I need to load data with variables
> > which are processed later. I used load 'filename', uigetfile, ... and
> > other conventional ways to load them but error message with unknown
> > variable is still showing up.
>
> Inside a function you should ALWAYS call LOAD in its function form with an
> output argument.
>
> data = load('wtr.mat');
> if data.x < 5
> % do something
> end
>
> If you need to refer to the x variable from wtr.mat using the name x, not
> the expression data.x, use:
>
> x = data.x;
>
> in your function after loading the data.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
Thanks, I am a bit closer to what I need. Problem still is, that I need to choose one parameter in first radio button group and in second radio button group I need to use those parameters for various simulations (depending what you choose in 2nd group) . Procedure you described works only if I load data under one of the 2nd button group and process them in the same function.
thanks
Jan

Subject: GUI to exe problem

From: Steven_Lord

Date: 21 Mar, 2013 21:07:21

Message: 6 of 7



"Jan " <urbanecjan@gmail.com> wrote in message
news:kifqop$kq1$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <kif1ob$mo6$1@newscl01ah.mathworks.com>...

*snip*

> Thanks, I am a bit closer to what I need. Problem still is, that I need to
> choose one parameter in first radio button group and in second radio
> button group I need to use those parameters for various simulations
> (depending what you choose in 2nd group) . Procedure you described works
> only if I load data under one of the 2nd button group and process them in
> the same function.

So you need to share data between the callback functions in your GUI? See
the two Data Management sections in the Concepts portion of this
documentation page:

http://www.mathworks.com/help/matlab/code-to-run-the-gui.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: GUI to exe problem

From: Jan

Date: 21 Mar, 2013 22:33:08

Message: 7 of 7

"Steven_Lord" <slord@mathworks.com> wrote in message <kifsq9$rcr$1@newscl01ah.mathworks.com>...
>
>
> "Jan " <urbanecjan@gmail.com> wrote in message
> news:kifqop$kq1$1@newscl01ah.mathworks.com...
> > "Steven_Lord" <slord@mathworks.com> wrote in message
> > <kif1ob$mo6$1@newscl01ah.mathworks.com>...
>
> *snip*
>
> > Thanks, I am a bit closer to what I need. Problem still is, that I need to
> > choose one parameter in first radio button group and in second radio
> > button group I need to use those parameters for various simulations
> > (depending what you choose in 2nd group) . Procedure you described works
> > only if I load data under one of the 2nd button group and process them in
> > the same function.
>
> So you need to share data between the callback functions in your GUI? See
> the two Data Management sections in the Concepts portion of this
> documentation page:
>
> http://www.mathworks.com/help/matlab/code-to-run-the-gui.html
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
Well, thanks. Finally I got it.
all I need is to use handles.
So my scrtip should looks like

handles.data = load('wtr.mat');
if handles.data.x < 5
    % do something
end

thanks again
regards Jan

Tags for this Thread

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.

Contact us