Help Please!!! (Beginner Learning) - Programmers Heaven

Howdy, Stranger!

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


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!!!


  • 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: ');

    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);

    See this example to learn how to handle more complex
Sign In or Register to comment.