Jump to content
Science Forums

Recommended Posts

Posted

Hi guys,

 

I'm having trouble figuring out how to read inputs from the arrow keys in matlab. I have a function which control an external board I have controlling a motor. I want to put this function in an if else type code so that if the button is pushed the function powers the board (sets value to 1) else the board return to no power (sets value to zero). I dont need to know how to tell it to go to one or zero just to tell it to use the function I already have when I push the arrow key.

 

Thanks in advance,

Oisin

Posted

I've never coded in Matlab, but if i'm not mistaken (and people that have done a fair share of matlab code will correct me if i'm wrong), this is done with the use of the input function

 

input(prompt_string, ['s']) where prompt string is the prompt, and 's' is an optional variable signifying to return a string rather then a numeric value

 

example

power_state=0;
power = input('Power up? (Y/N) [Y]: ', 's');
power = upper(power);
switch (power)
   case 'Y'
       power_state=1
   case 'N'
       power_state=0
   otherwise
       power_state=1
end

 

As to using arrow keys, as far as i can see there is no way to read continuous input from the keyboard, as i am not sure that Matlab was meant as that kind of a language. You could probably use Python with Matlab to achieve all that, or maybe call C functions to get your the input, but at the moment i can not find a way to read continuous input, i just dont think it was made to be that kind of a language...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...