Question

In: Computer Science

Matlab Given an array of monthly rainfall that covers some number of years (where each column...

Matlab

Given an array of monthly rainfall that covers some number of years

(where each column is a month and each row is a year)

create a function YEARLY that prints the average rainfall for each year

For example, if the information below were to be stored in a 5x12 matrix RAIN...

     J F M A M J J A S O N D
2003 1 2 1 2 1 2 1 2 1 2 1 2
2004 1 1 1 1 1 1 1 1 1 1 1 1
2005 2 2 2 2 2 2 2 2 2 2 2 2
2006 1 2 3 1 2 3 1 2 3 1 2 3
2007 5 1 2 4 3 3 5 1 2 4 3 3

Then the function YEARLY(RAIN) would print the result

average rainfall for year 1 is 1.500000
average rainfall for year 2 is 1.000000
average rainfall for year 3 is 2.000000
average rainfall for year 4 is 2.000000
average rainfall for year 5 is 3.000000

Note that only the rain amounts (not the labels) are stored in the input array (RAIN).

Solutions

Expert Solution

function [] = YEARLY(RAIN)
    x = 1;
    % iterating with seach row
    for row = RAIN.'
        % calculating average of row
        fprintf("average rainfall for year %d is %f\n",x,mean(row))
        x = x+1;
    end
end
% 
% RAIN = [
%     [1 2 1 2 1 2 1 2 1 2 1 2];
%     [1 1 1 1 1 1 1 1 1 1 1 1];
%     [2 2 2 2 2 2 2 2 2 2 2 2];
%     [1 2 3 1 2 3 1 2 3 1 2 3];
%     [5 1 2 4 3 3 5 1 2 4 3 3]
% ]

Code

Output


Related Solutions

Write a program in Java with a Scanner. Given an array and a number k where...
Write a program in Java with a Scanner. Given an array and a number k where k is smaller than the size of the array, write a program to find the k'th smallest element in the given array. It is given that all array elements are distinct. Example: Input: arr[] = {7,10,4,3,20,15} k = 3 Output: 7
write a code for given an array of integers where wachelement represents the maximum number...
write a code for given an array of integers where wach element represents the maximum number of jumps to reach the end of the array(starting from the first element) if an element O,then no jump can be made from that element if it is not possible to reach the end then output in c
[In MATLAB] We have an array of seven values for a number x : [ 1.92,...
[In MATLAB] We have an array of seven values for a number x : [ 1.92, 0.05, -2.43, -0.02, 0.09, 0.85 . 0.06] . We consider any data value in the range -0.1 <x<0.1 as erroneous value. We want to remove all such values and replace them with zeros at the end of the array. Write a script using a for loop with conditional statements Write a script using the find function
Given the following pairs of data where x is the number of years of experience in...
Given the following pairs of data where x is the number of years of experience in a certain company and y is the annual salary: Determine the equation of the linear regression line. Round the slope and y-intercept to the nearest integers. Using your answer in (a), estimate the starting salary for a new hire. Using your answer in (a), estimate the number of years (to the nearest year) an employee would have to work in the company in order...
How to print the element in the fifth row and seventh column given this array declaration...
How to print the element in the fifth row and seventh column given this array declaration in dev c: int hello[5][10];
1. Given an array of integers a dimension n. If the array contains the same number...
1. Given an array of integers a dimension n. If the array contains the same number of even and odd elements get (a1 + an) (a2 + an-1) ... 2. Given an array of integers dimension n. All array elements with even numbers preceding the first element to the maximum, multiplied by the maximum. 3. Given an array of dimension n. Insert after each zero element of the element in the middle (or the amount of secondary elements for even...
       Place an X in the Column for the financial statement where each is reported. It...
       Place an X in the Column for the financial statement where each is reported. It is possible for items to be reported on two statements. Income Balance Statement of Statement of Statement of Statement Sheet Cash Flows Retained Earnings Stocholders' Equity Buildings X Accounts Payable X Accounts Receivable X Bonds Payable X Cash X Cash paid for Salaries X Cash paid for Salaries X Cash paid to suppliers Cash Received from Customers Common Stock X Copyrights Cost of Goods...
Write a for-loop in MATLAB that generates a list of numbers such that each number is...
Write a for-loop in MATLAB that generates a list of numbers such that each number is the sum of the previous three. Initialize your list of numbers at the values of 0, 0 and 1. In other words, "0" is the first element of the list, "0" is the second element of the list, and "1" is the third element of the list. What is the 20th value in the list?
Assume that A and B are MATLAB arrays with 10 rows and an equal number of columns (the number of columns is not given).
Assume that A and B are MATLAB arrays with 10 rows and an equal number of columns (the number of columns is not given). Important: Next, the expression "a single line of code" implies a single command or equality. In other words, the code: X=A+1; X=X+B; is considered to be TWO lines of code, even though it can be written as one line. (a) (3%) Write a single line of code which saves the first two rows of array A...
Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.
Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.Input:    6    2 3 4 11 22 320    where:First line represents the number of elements in the array.Second line represents the elements in the array.Output:    2 3 4 11 22Explanation: Element of the array 320 is the only one in the array which is a multiple of 5, so it is removed from the array.Assumptions:Array can be of size...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT