Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ITP 168: Introduction to MATLAB Homework 4 Due: 11:59pm Feb 21, 2020 Setup: You will create a script that inputs a matrix, then sums the

ITP 168: Introduction to MATLAB

Homework 4 Due: 11:59pm Feb 21, 2020

Setup:

You will create a script that inputs a matrix, then sums the prime, odd or even numbers based on a user choice using loops.

Requirements:

  • Create a script file named: numbercalc.m

  • Using comments, put the following information at the top of the file:

    o Name o ITP168Fall2019 o Homework1 o USCEmail

    Include the clear and clc commands

    Part 1: User Input & Validation

    Ask the user to input a matrix of any size. Ensure that the user inputs a positive, integer matrix (HINT: the any() function could help here). If there is an incorrect input, ask them for a matrix again. Ask the user if they want to 1) sum the prime numbers in the matrix 2) sum the odd numbers or 3) sum the even numbers.

    Part 2: Summation of the matrix

    Once they choose, use a nested loop and conditionals to calculate the sum. You MUST use nested loops, vector math will not get credit.

    Part 3: Output the sum

    Output the sum to the user, and ask them if they would like to do another calculation. If they say yes, show the menu again and ask for another choice (hint: use a while loop). If they say N, then stop the program.

    Sample Output:

    This is a sample of what the program should show in the command window. If the user enters any information, it will be highlighted in RED:

    EXAMPLE 1

    Input a Matrix: [7 1 8; 4 5 8; 10 4 2] Please select from the following options:

  1. 1) Sum Prime Numbers

  2. 2) Sum Odd Numbers

  3. 3) Sum Even Numbers

1

The sum is 15 Would you like to do another calculation? Please select from the following options:

  1. 1) Sum Prime Numbers

  2. 2) Sum Odd Numbers

  3. 3) Sum Even Numbers

2

The sum is 13 Would you like to do another calculation? Please select from the following options:

  1. 1) Sum Prime Numbers

  2. 2) Sum Odd Numbers

  3. 3) Sum Even Numbers

3

The sum is 36 Would you like to do another calculation? Goodbye!

Example 2

Input a Matrix: [7 1 8; 4 5 8; 10 4 2] Please select from the following options:

  1. 1) Sum Prime Numbers

  2. 2) Sum Odd Numbers

  3. 3) Sum Even Numbers

7

Incorrect Input! Goodbye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

What will you do or say to Anthony about this issue?

Answered: 1 week ago