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

Assume that the monthly profits of a company are given in an array, each entry representing...
Assume that the monthly profits of a company are given in an array, each entry representing the profits for the corresponding month. Propose an algorithm to find a group of consecutive months where the profit was the highest. For example, the profits, in millions, for a year Jan-Dec is given by A=[2 -5 3 4 0 -1 5 8 -9 1 -2 0]; The highest profit was from the period March-August and the value is 19 million. Assume that the...
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
Given an array A[0 … n-1], where each element of the array represent a vote in...
Given an array A[0 … n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
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
Problem 1: Given an array A[0 ... n-1], where each element of the array represents a...
Problem 1: Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election. Problem 2: How do we find the number which appeared maximum number of times in an array? ( Use Java and an original code )
Using Java, Given an array A[0 ... n-1], where each element of the array represent a...
Using Java, Given an array A[0 ... n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
[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...
A) Suppose owls is a MATLAB array with 251 rows and 51 columns representing the number...
A) Suppose owls is a MATLAB array with 251 rows and 51 columns representing the number of owls counted in the 251 counties in Texas had over the years 1960-2010. Write code to define a MATLAB variable to find the median number of owls counted in each county. B) Suppose cattle is a MATLAB array with 251 rows and 51 columns representing the number of cattle in the 251 counties in Texas had over the years 1950-2000. Write code to...
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];
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT