using data generated in one callback in GUI in another callback in the same GUI

  • Follow


how do i use matrices i made in one push button callback func in the callback of another push button..
i thought a global matrix was created and was accessible anywhere in the m files... but thats not the case
0
Reply aashay 3/30/2010 9:17:24 PM

aashay vanarase wrote:
> how do i use matrices i made in one push button callback func in the 
> callback of another push button..
> i thought a global matrix was created and was accessible anywhere in the 
> m files... but thats not the case

'global' needs to be used in each routine that wishes to have access to the 
global variable.
0
Reply Walter 3/30/2010 9:21:37 PM


Walter Roberson <roberson@hushmail.com> wrote in message <hotq13$pov$3@canopus.cc.umanitoba.ca>...
> aashay vanarase wrote:
> > how do i use matrices i made in one push button callback func in the 
> > callback of another push button..
> > i thought a global matrix was created and was accessible anywhere in the 
> > m files... but thats not the case
> 
> 'global' needs to be used in each routine that wishes to have access to the 
> global variable.


how do i ensure my matrices are global??
0
Reply aashay 3/30/2010 9:29:05 PM

this doent seem to work, says unexpected {
global    m(index2)=mean2(y)
  global  red(index2)=sum(sum(y(:,:,1)))/(256*256)
 global   green(index2)=sum(sum(y(:,:,2)))/(256*256)
 global   blue(index2)=sum(sum(y(:,:,3)))/(256*256)
0
Reply aashay 3/30/2010 9:34:05 PM

aashay vanarase wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message 
> <hotq13$pov$3@canopus.cc.umanitoba.ca>...
>> aashay vanarase wrote:
>> > how do i use matrices i made in one push button callback func in the 
>> > callback of another push button..
>> > i thought a global matrix was created and was accessible anywhere in 
>> the > m files... but thats not the case
>>
>> 'global' needs to be used in each routine that wishes to have access 
>> to the global variable.
> 
> 
> how do i ensure my matrices are global??

Add the command


global NameOfTheMatrix


near the top of every routine that needs to access the global matrix named 
NameOfTheMatrix



To forestall a potential question: there is _no_ way to give a single command 
that means "The following variable name should be treated as global in every 
routine it is encountered in". You have to give the 'global' command in each 
routine that needs to use the variable.
0
Reply Walter 3/30/2010 9:35:31 PM

aashay vanarase wrote:
> this doent seem to work, says unexpected {
> global    m(index2)=mean2(y)
>  global  red(index2)=sum(sum(y(:,:,1)))/(256*256)
> global   green(index2)=sum(sum(y(:,:,2)))/(256*256)
> global   blue(index2)=sum(sum(y(:,:,3)))/(256*256)

global m
global red
global green
global blue

m(index2)=mean2(y)
red(index2)=sum(sum(y(:,:,1)))/(256*256)
green(index2)=sum(sum(y(:,:,2)))/(256*256)
blue(index2)=sum(sum(y(:,:,3)))/(256*256)

By the way, you can replace sum(sum(y(:,:,1)) by
   sum(reshape(y(:,:,1),[],1))
which will be faster


I am not convinced that dividing the sum by 256 * 256 is correct, not unless 
you are trying to take the mean value of a 256 x 256 array. If your array is 
uint8 and you are trying to convert the 0 to 255 values into 0 to 1 values and 
find the mean or "total power" of those, then your code is not correct. 
Suppose you had a 3 x 3 array whose value was all uint8(1), then the mean 
value would clearly be uint8(1), which would convert to 1/256 when adjusted to 
the 0 to 1 scale; likewise, the "total power" would be 9/256 when adjust to 
the 0 to 1 scale. The sum(sum()) would give 9 in this sample, which you would 
then divide by 256*256, which would give completely the wrong value for the 
mean, and would give an answer 1/256 too small for the "total power".
0
Reply Walter 3/30/2010 9:50:12 PM

5 Replies
147 Views

(page loaded in 0.038 seconds)


Reply: