Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB: Write a function called problem1 that takes a matrix A of positive integers as its sole input. If the assumption is wrong, the function

MATLAB:

Write a function called problem1 that takes a matrix A of positive integers as its sole input. If the assumption is wrong, the function returns an empty matrix. Otherwise, the function doubles every odd element of A and returns the resulting matrix. Notice that the output matrix will have all even elements. For example, the call B = hw3_problem1([1 4; 5 2; 3 1], will make B equal to [2 4; 10 2; 6 2]. PLEASE HELP I HAVE POSTED THIS MANY TIMES AND HAVE GOTTEN INCORRECT SOLUTIONS EVERY TIME. IT SHOULD WORK EVEN FOR INPUTS OF 1,2 (ETC.)

The code I have right now is:

function [retMat] = hw3_problem1(A) [m,n] = size(A); flag = 1; for i = 1:m for j = 1:n if A(i,j) < 0 flag = 0; end end end if flag == 0 retMat = []; else retMat = A; count = 1; for i = 1:m for j = 1:n if count % 2 == 1 retMat(i,j) = 2* A(i,j); end count = count + 1; end end end end

This works for input of 1 but fails for input of 2, Please help write a new code or by fixing this one. Much appreciated.

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

ISBN: 0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

What does the five-number summary consist of?

Answered: 1 week ago

Question

Identify and describe a suggested outline of a business plan.

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago