Question

Write a function with the header: function [out] = myDataTypeChecker(A,B) takes two matrices A and B...

Write a function with the header:

               function [out] = myDataTypeChecker(A,B)

takes two matrices A and B and has the following behavior (in this order):

  1. 1) if either A or B contains a “Not a Number”, the function should return -1.

  2. 2) if either A or B contains an +/-Infinity, the function should return -2

  3. 3) if either A or B is a character array, the function should return -3

  4. 4) if both A and B are logical arrays, the function should check to see if A and B

    are the same size.

    1. If they are not, it should return -4

    2. If they are, it should return the AND of A and B (an array indicating where

      both A and B are true)

  5. 5) if both A and B are numeric arrays, the function should check to see if A and B

    are the same size.

    1. If they are not, it should return -5

    2. If they are, it should return an array of the absolute value of the difference

      of A and B.

  6. 6) If A and B are not both logical arrays or not both numeric arrays,, it should return

    -6;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [ out ] = myDataTypeChecker( A,B )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
  
lenA = length(A);
lenB = length(B);
for i=1:1:lenA
if(isnan(A(i)))
out = -1;
return
end
end
  
for i=1:1:lenB
if(isnan(B(i)))
out = -1;
return
end
end
  
for i=1:1:lenA
if(isinf(A(i)))
out = -2;
return
end
end
  
for i=1:1:lenB
if(isinf(B(i)))
out = -2;
return
end
end
  
if(ischar(A) || ischar(B))
out = [-3];
return
end
if(islogical(A) && islogical(B))
if(length(A) == length(B))
out = and(A,B);
return
else
out = -4;
return
end
  
elseif(isnumeric(A) && isnumeric(B))
if(length(A) == length(B))
out = abs(A-B);
return
else
out = -5;
return
end
end
out = -6;

end

The matlab function is provided for the requirement specified.

Please like,

:-)

Thank you for your support.

Add a comment
Know the answer?
Add Answer to:
Write a function with the header: function [out] = myDataTypeChecker(A,B) takes two matrices A and B...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...

    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.

  • Write a C function that takes two strings (character arrays) as input and return 1 if...

    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...

    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.

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • Write a mips program that defines two integer array that are pre-sorted and the same size...

    Write a mips program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6,...

  • Write a method that takes two arrays of integers and return and array that is the...

    Write a method that takes two arrays of integers and return and array that is the union of both arrays. For instance, the first array contains (1,2,3), the second array(4,5,6), the returned array should contain (1,2,3,4,5,6) (3.5 points) Write a method that takes and an array and return the reverse of that array. For instance, if the array is (1,2,3), the returned array should be (3,2,1) (3.5 points)

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • Write a function to add two one-dimensional matrices of integer values. The matrices are represented as...

    Write a function to add two one-dimensional matrices of integer values. The matrices are represented as arrays of int and the function must return the result as a pointer to a new dynamically allocated array of int. You can assume the parameters are always of length greater than 0 and that no errors can occur.

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • Question 2 In this question, you will read two data files that include integers into two...

    Question 2 In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok. 1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays). 2- Include a printArray function so that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT