Question

create program using matlab, that displays number of (+) entries (=>0) in matrix and number of...

create program using matlab, that displays number of (+) entries (=>0) in matrix and number of negative (<0). Hard code matrix in program. Use nested loops and an if-else-end structure to count (+) and (-) entries. Program should display original matrix and number of positive/negative entries.

Homework Answers

Answer #2

Matlab Code:

m=input('Enter number of rows ');
n=input('Enter number of columns');
c=0; d=0;
for i=1:m
for j=1:n
a(i,j)=input('Input elements row wise-\n');
end
end
a=reshape(a,m,n);
for i=1:m
for j=1:n
if a(i,j)>0
c = c+1;
else
d = d+1;
end
end
end
fprintf('Number of +ve entries = %d\n',c)
fprintf('Number of -ve entries = %d\n',d)

Output:

Enter number of rows 2
Enter number of columns2
Input elements row wise-
2
Input elements row wise-
2
Input elements row wise-
3
Input elements row wise-
4
the matrix is:

a =

2 2
3 4

Number of +ve entries = 4
Number of -ve entries = 0

answered by: anonymous
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
create program using matlab, that displays number of (+) entries (=>0) in matrix and number of...
create program using matlab, that displays number of (+) entries (=>0) in matrix and number of negative (<0). Hard code matrix in program. Use nested loops and an if-else-end structure to count (+) and (-) entries. Program should display original matrix and number of positive/negative entries.
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is...
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is equal to the sum of its row and column number, except for the diagonal elements which are zeros
Using a loop (not the output format character %o), create a program that takes a positive...
Using a loop (not the output format character %o), create a program that takes a positive integer n, and then displays the polynomial for the octal representation of that integer. Use successive division, as demonstrated in the binary conversion example from the lesson, to do this. For example, for n = 157, the program should output the following: 157 = + (5 * 8^0) + (3 * 8^1) + (2 * 8^2) When this part is working properly, “surround” this...
Game to guess a number %% Guess Number Game while(1) count=0; guess=input('Guess a number between 0...
Game to guess a number %% Guess Number Game while(1) count=0; guess=input('Guess a number between 0 to 10 '); if(R>guess) disp('Your guess is too small') elseif (R<guess) disp('Your guess is too large') elseif (R==guess) disp('You are correct! It is ');guess R=floor( rand()*10 ); end count=count+1; if(count==3) break; end end You need to modify this code: (1)Player fails the game if you cannot make it within 3 tries. (2)Player can do this game up to 10 times. (3)If player input is...
C++ code please: Write a program to count the number of positive and the number of...
C++ code please: Write a program to count the number of positive and the number of negative inputs values. The program will stop when a 0 is input. Ex: If the input is -5.5 568 2.332 0 the output is 2 positive number(s) and 1 negative number(s). Ex: If the input is 153.0 0.534 2.2 5.6 46.584 0.015 5 0 the output is 7 positive number(s) and 0 negative number(s).
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the following problem: The heating system in a school should be switched on if the average temperature is less than 17 degrees Celsius. The average temperature is found from the temperatures in the Math, English and IT departments. You are required to write a program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The program works with a single digit. The default value is 6, but user to change it as a menu selection. 2.      Program should display the patterns below. Additionally, you need to create your own pattern. 3.      Do not modify myPatterns6 driver. 4.      Make sure you document the program and its functions. 5.      PatternI is already implemented. 6.      Create five additional functions (similar to PatternI function) to implement Patterns II,...
Write a program using Matlab that asks the user for their last three grades and final...
Write a program using Matlab that asks the user for their last three grades and final grade and gives them their overall final grade. The three Midterms are worth 70% and Final is worth 30%. The program will display their Final grade with a grade letter corresponding to it. Run your program and verify that it operates correctly (hint: you might need to use “If, else statements”)
Write a program to count number between 0 and 255 in binary using 8 LEDs connected...
Write a program to count number between 0 and 255 in binary using 8 LEDs connected to the Arduino. This code should start at 0 and loop back to 0 once it counts to 255. Delay 0.25s between counts.
Using the Java language program Demonstrate multiway if statement 1.1 Generate an integer random number from...
Using the Java language program Demonstrate multiway if statement 1.1 Generate an integer random number from -5 to 5.(Hint: Use Math.random()) 1.2 Write a multiway if statement that will display whether the number is positive, negative or zero. 1.3 Be sure to test your code with all three cases