Question

1. (10 pts) Write a function called hws_problem1 that accepts three input arguments: 1) a 3-column string matrix (say names), 2) a 4-column numeric matrix (say, numbers), and 3) a scalar threshold value (say, threshold). Note that the names matrix is the new string type that uses double quotes. The first two input arguments contain information about U.S. astronauts, where each corresponding row of the two matrices represents a single astronaut. The columns of the two matrices contain the following information for an astronaut: -First name: first column of names. - Middle name: second column of names. -Last name: third column of names. - Month of birth: first column of numbers. - Day of birth: second column of numbers. - Year of birth: third column of numbers. - Hours in space: fourth column of numbers. The function should return a struct array containing the information about astronauts whose hours in space exceed the given threshold (the third input argument). For example, given the following matrices for names and numbers, respectively: names Malcolm ScottCarpenter Leroy Gordon Cooper Jr.; JohnHerschel Glenn Jr.; VirgilIvan WalterMartySchirra 3r. Grissom numbers [5 1 1925 4; 3 6 1927 225; 7 18 1921 217; 4 3 1926 5; 3 12 1923 295 ]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
hw5_problem1.m
function [output] = hw5_problem1(names, numbers, threshold)
% getting the column numbers of the elements greater then threshod
% in numbers
[col] = find(numbers(:,4) > threshold);
output = [];
% looping for each column
for indx = 1:numel(col)
    % assembling a new struct for each index position
    new_struct.first = names(col(indx, 1), 1);
    new_struct.middle = names(col(indx, 1), 2);
    new_struct.last = names(col(indx, 1), 3);

    new_struct.birth_month = numbers(col(indx, 1), 1);
    new_struct.birth_day = numbers(col(indx, 1), 2);
    new_struct.birth_year = numbers(col(indx, 1),3);
    new_struct.hours_in_space = numbers(col(indx, 1),4);
    % appending the struct as a vector to output
    output = [output, new_struct];

end
end
hw5_problem1_driver.m ( Run this file, not the above one)
clc
clear all

names = ["Malcolm" "Scott" "Carpenter";
        "Leroy" "Gordon" "Cooper Jr.";
        "John" "Herschel" "Gleen Jr.";
        "Virgil" "Ivan" "Grissom";
        "Walter" "Marty" "Schirra Jr."];
numbers = [5 1 1925 4;
           3 6 1927 225;
           7 18 1921 217;
           4 3 1926 5;
           3 12 1923 295];
output = hw5_problem1(names, numbers, 200)
output(1)
output(2)
output(3)

OUTPUT

Command Window output- 1x3 struct array with fields: first middle last birth month birth_day birth_year hours in space ans = struct with fields: first: Leroy middle: Gordon last: Cooper Jr. birth_month: 3 birth day: 6 birth year: 1927 hours in space 225

Add a comment
Know the answer?
Add Answer to:
1. (10 pts) Write a function called hws_problem1 that accepts three input arguments: 1) a 3-column...
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
  • Write a C program that includes a function called moveEm() that accepts the ADDRESSES of three...

    Write a C program that includes a function called moveEm() that accepts the ADDRESSES of three double variables as input. The function should move the value of the smallest variable into the first variable, the middle value into the middle variable, and the largest value into the third variable. Call your function from within your program using the arguments 7.8, 3.5, and 1.1 in order to demonstrate that it works (make sure your logic works for any order of largest,...

  • Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel...

    Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMin must work when called with various types of actual arguments, for example string DisplayMin(string names[], int calories[], int size) or int DisplayMin(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

  • Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have...

    Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have two required arguments and two keyword arguments. The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5. Test it twice from...

  • Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have...

    Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have two required arguments and two keyword arguments. The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5. Test it twice from...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • C++ Simple Employee Tracking System

    This assignment involves creating a program to track employee information.  Keep the following information on an employee:1.     Employee ID (string, digits only, 6 characters)2.     Last name (string)3.     First Name (string)4.     Birth date (string as MM/DD/YYYY)5.     Gender (M or F, single character)6.     Start date (string as MM/DD/YYYY)7.     Salary per year (double)Thus you must create a class that has all of this, and get/set methods for each of these fields.  Note: The fields that are designated as string should use the string...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

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