MATLAB
Write a function maxContent(arr) that takes a cell array arr as input and returns the longest string and largest number in arr. If there are two character arrays of same length, the function should return one of them. Assume that integers in the cell array are nonnegative.
function [ word, number] = MaxContent( arr)
%
L = cellfun('length',arr); % here we compute the length
% of the elements in the cell array
[m, i] = max(L);
word = arr(i); % word holds the longest string
fprintf('The longest string is:');
disp(word);
dim = size(arr,1); % get the lenght of the cell array
number = 0;
for i=1:dim
if(L(i) == 1)
if(cell2mat(arr(i))>number)
number = cell2mat(arr(i));
end
else
continue;
end
end
fprintf('Maximum integer is %d',number);
end
MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...
2a) Write a method countEvens that takes an ArrayList of String objects as input and returns the number of even length strings contained in the input. For example, if the input is [ one, peach, pear, plum ] then countEvents(inp) should return 2. 2b) Write a method, mirror, that doubles the size of a list of integers by appending a mirror image of the list. For example, given an array list containing [ 1, 5, 2, 6 ], the method...
write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...
Write a function that takes as input parameters an array of characters and a length field. The function will create a square matrix from the array by first determining the largest square matrix that will hold as many numbers as possible yet not have any blank spaces. So, for instance, if the array’s length was 22, the largest square matrix would be 4x4. If the array’s length was 37, the square matrix would be 6x6. Then create the square matrix...
PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...
Write the function compute_histogram, in Matlab, that takes a grayscale image as input and returns a length 256 vector h which is the normalized histogram of the values in the image. h should have values from 0 to 1 and its components should sum to 1.
MATLAB function Write an efficient function, f(v) that takes a one-dimensional array of length N^2 for a square matrix (in a row-vectorized form) as an input and returns the trace of the matrix.
Do the following: - Write and test a function that takes an array of doubles and returns the average of the values in the array - Write and test a function that takes an array of doubles and returns number of values in the array that are above the average of the values in the array - Write and test a function that takes an array of Strings and returns number of values in the array that start with an...
Write a C function that takes two strings (character arrays) as input and return 1 if they are equal and return 0 if they re not. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal in the same order.
Write a C function that takes two strings (character arrays) as input and return 1 if they are equal and return 0 if they re not. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal in the same order.
1- takes a 1D integer array arr as a parameter and returns a boolean value. 2- The method returns true if the argument array contains two distinct values such that the sum of those two values is equal to the first element of the array arr. Otherwise, it returns false. 3- Assume that arr contains only positive integers (greater than 0). Sample runs provided below. 4- Sample runs provided below. 5- Complete and place your code in the Question 3...