Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9298899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:26:05+00:00 2026-06-18T22:26:05+00:00

I have a function that I would like to take input for but only

  • 0

I have a function that I would like to take input for but only when the user wants to. For example if i have this code:

figure
amplitude = 10;
tic
i = 1;
while(1) 
    time = toc;
    values(i) = amplitude*sin(time);
    times(i) = time;
    plot(times, values)
    drawnow
    i = i+1;
end

You will get a continually plotting sine wave (like a lame movie). What I want to do is allow the user to change the amplitude of the wave at any time. That is the program will continue to run but if the user types in 20 and Enter then the amplitude variable can be changed and the sine wave will change amplitude in the movie. Any pointers on how to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:26:06+00:00Added an answer on June 18, 2026 at 10:26 pm

    It is probably best to do it with a GUI as mentioned, but if you just want something in the console here is what I can offer:

    A script that periodically asks the user to input an amplitude and then continues the ‘movie’ with this amplitude. It can easily be expanded to allow the user to decide when he will be asked to input the next amplitude change.

    clear
    amplitude = 10;
    i=1;
    while(1) 
        time = i/1000;
        values(i) = amplitude*sin(time);
        times(i) = time;
        plot(times, values)
        drawnow
        i = i+1;
        if mod(i,3141) == 0
            keyboard
        end
    end
    

    Now this will run for a while and then ask you to input the next amplitude. Note that you can actually give multiple commands at once.

    amplitude = 20; return
    amplitude = 1; return
    

    This will let the next amplitude be 20 and the one after that 1. Note that the upward arrow key is your friend here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function that I would like to condense into some iterator. How
I would like to have a mapping function that does this: public static void
I'd like to write a function that would have some optional code to be
I have this line: $(#clients-edit-wrapper).height($(window).height()-150); I would like to apply that height function to
I have a function that I would like to return 0 if a certain
I would like to have a function that can wrap any other function call.
I have a function that I use on index.php page and I would like
I have a function that is side-effect free. I would like to run it
I have a dataframe and I would like to apply a function that takes
PHP: I have made up a function that returns an array. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.