Info

This question is closed. Reopen it to edit or answer.

i have a programming project in my class and i have no idea where to start if some one can help me please

1 view (last 30 days)
Write a Matlab script that does the following:
1. Prompts the user for a vector consisting of integers: 0, ±1, ±2, ±3, . . .
2. Returns to the screen the decimal number that is formed by replacing all negative numbers by a zero.
3. If the user inputs a vector that contains one or more numbers that are not integers (for example: [ 8 2.1 −9 ]), the script should notify the user that their input is incorrect.
4. The script should ask the user whether they want to run the program again.
Test your program with at least 2 different entries. An example output could look as follows:
Please enter a vector consisting of integers: [2 -3 4 -5]
The decimal number is: 2040
Again (y/n)? y
Please enter a vector consisting of integers: [3 2.2 8 5]
Incorrect entry!
Again (y/n)? y
Please enter a vector consisting of integers: [-7 3 2 -5 -4 1]
The decimal number is: 32001
Again (y/n)? n
  1 Comment
John D'Errico
John D'Errico on 20 Sep 2015
You start by writing code! As I have been known to say, you eat a programming elephant one byte at a time.
Solve one small chunk. For example, how do you input the numbers? Learn to use the tools in MATLAB. Here for example, you might start by reading the help for input.
Then you need to test the numbers.
Then you will figure out how to use an if statement. And then a while loop to continue the process until you are happy. And, as for converting a string of digits to an integer, think about it. What does it mean to be a base 10 integer? Or, you can be lazy, and use base2dec.
Do it ONE piece at a time. Make sure that each section, each code fragment, works before you start on the next.
The only way you will learn is by starting to write.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!