KeyPressFcn

jinji0

New member
KeyPressFcn

אני עובד בMATLAB ורוצה לייצור פונקציה שתרוץ כאשר אני לוחץ על מקש מסויים במקלדת (למשל הסיפרה Ctrl+1 וכו'..) איך אני בונה כזאת פקודה? קראתי על הפונקציה KeyPressFcn ולא הצלחתי להבין את אופן השימוש בה...
 

ronitV

New member
אולי משהו כזה

function ShowGraphs % Create a figure and specify a KeyPressFcn callback figure('KeyPressFcn',@kbdCallback) % Callback subfunction header function kbdCallback(obj,eventdata) % Determines which key was pressed kbd=get(gcf,'CurrentCharacter'); x = 1:0.01:10; switch kbd case 'x' y = x.^3; case 'y' y = x.^2; end plot(x,y);​
שמור את הפונקציה בקובץ ShowGraphs.m ותריץ אותה, תראה אם זה מה שאתה צריך.
 
למעלה