How can I output variables from a handle function passed as param to a set function?

조회 수: 2 (최근 30일)
Hello,
I would like to use an output variable generated inside a handle function which is passed as parameter to a set function. I mean, I have a main code (which I haven´t added here so as not to complicate my question). In this main code,I call the function frying_pan_position_keypress(y). Then, when I press the left arrow key, eg, I calculate te variable j, and I would like to pass this variable to the main code.
This is my code:
function j=frying_pan_position_keypress(y)
set(gcf,'KeyPressFcn',{@frying_pan_movement,y});
function j=frying_pan_movement(scr,event,y)
switch event.Character
case 28
j=y-2
case 29
j=y+2
case 30
j=y-10
case 31
j=y+10
end
end
end
Lots of thanks in advance.

답변 (2개)

Joseph Cheng
Joseph Cheng 2014년 3월 14일
편집: Joseph Cheng 2014년 3월 14일
edit: did a quick mockup and maybe easiest way is to just create a global variable? Probably not the Best solution.

Armando  Perez
Armando Perez 2014년 3월 16일
First of all, I would like to thank you for being so fast at the time to answer my question.
I have already tried to create ''j'' as global variable but it doesn´t work. The ''j'' outside and the ''j'' inside the handle function is a different variable. What I think I need is to be able to get j as an ouput from function set which is the link between the funcion and the handle function.
I have read that help in stackoverflow before but it is only explained how to use and create keyboard interruptions and its handle functions. And it doesn´t explain how to get a variable outside it to be able to use it in a main program.
I'm going to keep in it but any help will be very useful.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by