Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help Please!!! (Beginner Learning)

SilentOSilentO Posts: 7Member
I have just started learning to program using Matlab. I would like to learn how to create the following user inputs into an array,

1) Prompt user to input how many number that array will have
N = input('Enter the number of element the array has: ');

2) Prompt the user to input the number for the first element of the array until the nth of the element? (Prompt must displays which element of the array it is asking for the input)

3) Print out the element of the array.

For Example,

Enter the number of element of the array has: 4

Enter the number for the 1 element of the array: 5
Enter the number for the 2 element of the array: 7
Enter the number for the 3 element of the array: 7
Enter the number for the 4 element of the array: 7


Please help!!!

Comments

  • SilentOSilentO Posts: 7Member
    something like this,

    Degree = input('Enter the degree of the polynomial: ' );
    for i = Degree+1:-1:1
    if i == 11
    C(i) = input ('Enter the coefficence a10: ');
    elseif i == 10
    C(i) = input ('Enter the coefficence a9: ');
    elseif i == 9
    C(i) = input ('Enter the coefficence a8: ');
    elseif i == 8
    C(i) = input ('Enter the coefficence a7: ');
    elseif i == 7
    C(i) = input ('Enter the coefficence a6: ');
    elseif i == 6
    C(i) = input ('Enter the coefficence a5: ');
    elseif i == 5
    C(i) = input ('Enter the coefficence a4: ');
    elseif i == 4
    C(i) = input ('Enter the coefficence a3: ');
    elseif i == 3
    C(i) = input ('Enter the coefficence a2: ');
    elseif i == 2
    C(i) = input ('Enter the coefficence a1: ');
    elseif i == 1
    C(i) = input ('Enter the coefficence a0: ');
    end
    end

    but simplify the else if state to just from degree+1 to 1
  • SilentOSilentO Posts: 7Member
    This post has been deleted.
  • SilentOSilentO Posts: 7Member
    This post has been deleted.
  • jjasso5jjasso5 Posts: 41Member
    Try this:

    n = input('Number of elements: ');
    for i = 1:n
    str = ['Element ' num2str(i) ': '];
    e(i) = input(str);
    end
    e


    See this example to learn how to handle more complex
    strings:

    http://www.matrixlab-examples.com/check-writer.html
Sign In or Register to comment.