Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1498
Number of posts: 2178

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help Please!!! (Beginner Learning) Posted by SilentO on 21 Mar 2010 at 5:49 PM
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!!!

Report
Re: Help Please!!! (Beginner Learning) Posted by SilentO on 22 Mar 2010 at 4:33 PM
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
Report
Re: Help Please!!! (Beginner Learning) Posted by jjasso5 on 26 Mar 2010 at 2:45 PM
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
Report
This post has been deleted. Posted by SilentO on 22 Mar 2010 at 4:35 PM
This post has been deleted.
Report
This post has been deleted. Posted by SilentO on 22 Mar 2010 at 4:36 PM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.