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:
Noob question

Subject: Noob question

From: Joshua

Date: 17 Nov, 2010 19:30:26

Message: 1 of 13

Hi, i'm new to Matlab.
Was workiing on a GUI with Matlab.

During the coding of the GUI, I created a variable within a function.
For eg,
function F1_Callback(hObject, eventdata, handles)
      M = imread(fullfile(pathname, filename));

When i try to use the variable in another function,
For eg,
function F2_Callback(hObject, eventdata, handles)
BW = dither(M)

and it gaves me
??? Undefined function or variable 'M'.

Anyone can help me out, please?

Subject: Noob question

From: Sean de

Date: 17 Nov, 2010 19:44:04

Message: 2 of 13

"Joshua " <junyeeng@yahoo.com> wrote in message <ic1agh$et7$1@fred.mathworks.com>...
> Hi, i'm new to Matlab.
> Was workiing on a GUI with Matlab.
>
> During the coding of the GUI, I created a variable within a function.
> For eg,
> function F1_Callback(hObject, eventdata, handles)
> M = imread(fullfile(pathname, filename));
>
> When i try to use the variable in another function,
> For eg,
> function F2_Callback(hObject, eventdata, handles)
> BW = dither(M)
>
> and it gaves me
> ??? Undefined function or variable 'M'.
>
> Anyone can help me out, please?

M has not been defined in the new function and thus it is not useable by it. Make it useable by passing it with:
doc setappdata
doc getappdata

Subject: Noob question

From: Joshua

Date: 17 Nov, 2010 20:51:04

Message: 3 of 13


> M has not been defined in the new function and thus it is not useable by it. Make it useable by passing it with:
> doc setappdata
> doc getappdata

thx for help, now.. what is handle?
the data i want to pass is an image, can setappdata and getappdata pass image file using handle?
(Oh god, what am i askin)

Subject: Noob question

From: Sean de

Date: 17 Nov, 2010 21:01:06

Message: 4 of 13

"Joshua " <junyeeng@yahoo.com> wrote in message <ic1f7n$1uf$1@fred.mathworks.com>...
>
> > M has not been defined in the new function and thus it is not useable by it. Make it useable by passing it with:
> > doc setappdata
> > doc getappdata
>
> thx for help, now.. what is handle?
> the data i want to pass is an image, can setappdata and getappdata pass image file using handle?
> (Oh god, what am i askin)

Why pass the handle? Just pass the image:
in function 1:
I = imread(...
setappdata(0,'The_Image',I);

in function 2:
I = getappdata(0,'The_Image');

Subject: Noob question

From: Bruno Luong

Date: 17 Nov, 2010 21:11:04

Message: 5 of 13

> Why pass the handle? Just pass the image:
> in function 1:
> I = imread(...
> setappdata(0,'The_Image',I);
>
> in function 2:
> I = getappdata(0,'The_Image');

I disagree, passing handle 0 is like using global variable. This is not clean programming and a bad habit.

There are at least five ways of passing data among Callbacks.

1) guidata
2) setappdata/getappdata
3) using the field 'userdata' of graphic handles
4) using nested functions
5) using global variables

I prefer them by order they are listed.

Bruno

Subject: Noob question

From: Joshua

Date: 17 Nov, 2010 21:23:04

Message: 6 of 13

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> Why pass the handle? Just pass the image:
> in function 1:
> I = imread(...
> setappdata(0,'The_Image',I);
>
> in function 2:
> I = getappdata(0,'The_Image');

Many many thx for the demonstation.
got it

Subject: Noob question

From: Walter Roberson

Date: 17 Nov, 2010 21:43:59

Message: 7 of 13

On 10-11-17 03:11 PM, Bruno Luong wrote:

> There are at least five ways of passing data among Callbacks.
>
> 1) guidata
> 2) setappdata/getappdata
> 3) using the field 'userdata' of graphic handles
> 4) using nested functions
> 5) using global variables
>
> I prefer them by order they are listed.

Bruno, would you consider writing this up in the FAQ ?

http://matlab.wikia.com/wiki/FAQ

Subject: Noob question

From: Bruno Luong

Date: 17 Nov, 2010 22:28:04

Message: 8 of 13

Walter Roberson <roberson@hushmail.com> wrote in message <ic1ib4$gtl$1@canopus.cc.umanitoba.ca>...

>
> Bruno, would you consider writing this up in the FAQ ?
>
> http://matlab.wikia.com/wiki/FAQ

Thanks Walter for the head up, I'll consider.

Bruno

Subject: Noob question

From: someone

Date: 17 Nov, 2010 22:39:04

Message: 9 of 13

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ic1ktk$mgj$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <ic1ib4$gtl$1@canopus.cc.umanitoba.ca>...
>
> >
> > Bruno, would you consider writing this up in the FAQ ?
> >
> > http://matlab.wikia.com/wiki/FAQ
>
> Thanks Walter for the head up, I'll consider.
>
> Bruno

Isn't it already in Q5.16?
Or are you proposing adding something?

Subject: Noob question

From: Walter Roberson

Date: 17 Nov, 2010 22:58:19

Message: 10 of 13

On 10-11-17 04:39 PM, someone wrote:
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> <ic1ktk$mgj$1@fred.mathworks.com>...
>> Walter Roberson <roberson@hushmail.com> wrote in message
>> <ic1ib4$gtl$1@canopus.cc.umanitoba.ca>...
>>
>> > > Bruno, would you consider writing this up in the FAQ ?
>> > > http://matlab.wikia.com/wiki/FAQ
>>
>> Thanks Walter for the head up, I'll consider.
>>
>> Bruno
>
> Isn't it already in Q5.16?
> Or are you proposing adding something?

You are right, Q5.16; I did not see it .

I've been thinking that people could use an outline of the pros/cons of the
various possibilities, but perhaps that is too involved for a FAQ.

Subject: Noob question

From: Bruno Luong

Date: 17 Nov, 2010 22:59:06

Message: 11 of 13

"someone" <someone@somewhere.net> wrote in message <ic1li8$4dv$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ic1ktk$mgj$1@fred.mathworks.com>...
> > Walter Roberson <roberson@hushmail.com> wrote in message <ic1ib4$gtl$1@canopus.cc.umanitoba.ca>...
> >
> > >
> > > Bruno, would you consider writing this up in the FAQ ?
> > >
> > > http://matlab.wikia.com/wiki/FAQ
> >
> > Thanks Walter for the head up, I'll consider.
> >
> > Bruno
>
> Isn't it already in Q5.16?
> Or are you proposing adding something?

Right. One to-do task less. ;-)

Subject: Noob question

From: Steven_Lord

Date: 18 Nov, 2010 15:09:21

Message: 12 of 13



"Walter Roberson" <roberson@hushmail.com> wrote in message
news:ic1mmh$np8$1@canopus.cc.umanitoba.ca...
> On 10-11-17 04:39 PM, someone wrote:
>> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
>> <ic1ktk$mgj$1@fred.mathworks.com>...
>>> Walter Roberson <roberson@hushmail.com> wrote in message
>>> <ic1ib4$gtl$1@canopus.cc.umanitoba.ca>...
>>>
>>> > > Bruno, would you consider writing this up in the FAQ ?
>>> > > http://matlab.wikia.com/wiki/FAQ
>>>
>>> Thanks Walter for the head up, I'll consider.
>>>
>>> Bruno
>>
>> Isn't it already in Q5.16?
>> Or are you proposing adding something?
>
> You are right, Q5.16; I did not see it .

ImageAnalyst asked for that very same type of thing two and a half weeks ago
and you replied in that thread. He had suggested the use of MAT-files as
another approach, in addition to the five Bruno brought up, while you
suggested memory mapped files and databases be included if the FAQ entry was
to contain an attempt at a comprehensive list.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/295327

2 November, titled "Image stack display in GUI with slider control"

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

Subject: Noob question

From: Walter Roberson

Date: 18 Nov, 2010 16:27:59

Message: 13 of 13

On 18/11/10 9:09 AM, Steven_Lord wrote:

> ImageAnalyst asked for that very same type of thing two and a half weeks
> ago and you replied in that thread.

Heh. At least I'm consistent as my memory fails me ;-)

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