Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: How can I read input from the keyboard?

Subject: How can I read input from the keyboard?

From: Shiyuan Gu

Date: 27 Mar, 2008 22:17:02

Message: 1 of 8

Any function for read input from the keyboard?
Thank you

Subject: How can I read input from the keyboard?

From: Sven

Date: 28 Mar, 2008 02:09:02

Message: 2 of 8

"Shiyuan Gu" <gshy2014@gmail.com> wrote in message
<fsh6cu$kku$1@fred.mathworks.com>...
> Any function for read input from the keyboard?
> Thank you

Yes, gtext will prompt the user to write some text that you
can store to a variable.

Cheers,
Sven.

Subject: How can I read input from the keyboard?

From: Miroslav Balda

Date: 28 Mar, 2008 09:59:02

Message: 3 of 8

"Shiyuan Gu" <gshy2014@gmail.com> wrote in message
<fsh6cu$kku$1@fred.mathworks.com>...
> Any function for read input from the keyboard?
> Thank you
Hi
The standard function of MATLAB for reading frpm keyboard is
the function 'input'. There is still another function 'inp'
in the collection of users' function File Exchange. It
enables to preset default value, which can be changed by
user's input. The function inp may be found at FEX Id. 9033.
Mira

Subject: How can I read input from the keyboard?

From: Michal S

Date: 24 Apr, 2008 07:25:05

Message: 4 of 8

And is there some function reading actual stdin buffer
state? What I need to do is to keep drawing a graph (in a
while(1) loop) and I want to break it when a user pushes
some button.

How to do this- each funciotn I've seen WAITS for a user
action. Is there no single one that just watches the
keyboard buffer state without stopping a running program?

Thanks in advance for your support

Subject: How can I read input from the keyboard?

From: Jos

Date: 24 Apr, 2008 08:31:02

Message: 5 of 8

"Michal S" <miqba@szczecin.home.pl> wrote in message
<fupckg$ail$1@fred.mathworks.com>...
> And is there some function reading actual stdin buffer
> state? What I need to do is to keep drawing a graph (in a
> while(1) loop) and I want to break it when a user pushes
> some button.
>
> How to do this- each funciotn I've seen WAITS for a user
> action. Is there no single one that just watches the
> keyboard buffer state without stopping a running program?
>
> Thanks in advance for your support


You can use properties of the figure. For instance, try this

figh = figure(...
   'keypressfcn','set(gcbf,''userdata'',1)', ...
   'userdata',0) ;
figure(figh) ;
while ~get(figh,'userdata'),
  plot(rand(10)) ; % some plot function
  drawnow ;
end
 
hth
Jos

Subject: How can I read input from the keyboard?

From: Michal S

Date: 24 Apr, 2008 15:18:01

Message: 6 of 8

Thanks for reply. It may work, but it doesn't solve my
problem at all.

Basicly I do not use plot() (I just wrote it to make it
easier to explain).

What I do is getting data via serial port and filtering it
in Matlab, then I use a freeware oscilloscope software
(http://www.oscilloscope-lib.com/) to draw it. I tried
using build-in Matlab plot functions but it didn't work for
really fast transfers.

Anyway- I need some universal function that'll allow me
stop an endless loop by pressing "anything". It may be a
keyboard button, it may be some part of GUI as well.

I tried to do it various ways, but neither works.

I want to do something like:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while(1)
data=fscanf(...);
oscmx(7,[data]); %drawing data
if(keyboard_pressed()) break;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

And that's all!
Like I said -it doesn't have to be a keyboard button. It
can be some GUI stuff, but I'm not familliar with it and
all these callback functions doesn't work like they seem to
 :P (I've got huge problems with passing data in and out of
them- Matlab doesn't have pointers and global variables are
also "not so global" as it should be).

Any ideas?
Thanks in advace

Subject: How can I read input from the keyboard?

From: Steven Lord

Date: 24 Apr, 2008 18:31:40

Message: 7 of 8


"Michal S" <miqba@szczecin.home.pl> wrote in message
news:fuq8b9$ren$1@fred.mathworks.com...
> Thanks for reply. It may work, but it doesn't solve my
> problem at all.
>
> Basicly I do not use plot() (I just wrote it to make it
> easier to explain).
>
> What I do is getting data via serial port and filtering it
> in Matlab, then I use a freeware oscilloscope software
> (http://www.oscilloscope-lib.com/) to draw it. I tried
> using build-in Matlab plot functions but it didn't work for
> really fast transfers.

I'm guessing you were calling PLOT repeatedly in a loop, yes? Rather than
doing that, you should try SETting the XData and YData of the line whose
handle you generated using PLOT before the loop.

> Anyway- I need some universal function that'll allow me
> stop an endless loop by pressing "anything". It may be a
> keyboard button, it may be some part of GUI as well.

In that case, try this:

http://www.mathworks.com/support/solutions/data/1-15JIQ.html?solution=1-15JIQ

*snip*

--
Steve Lord
slord@mathworks.com


Subject: How can I read input from the keyboard?

From: Michal S

Date: 24 Apr, 2008 20:22:01

Message: 8 of 8

Actually I found something that did the trick. If any would
have similar problems there is a topic with almost
identical case:
http://www.mathworks.com/matlabcentral/newsreader/
view_thread/162844

And tutorial showing how to do that:
http://www.blinkdagger.com/matlab/matlab-gui-tutorial-how-
to-stop-a-long-running-function

Anyway thanks a lot for your support :)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics