Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Matlab) In this problem, write the first of two functions. This first function takes in the first and last name and returns a string that

(Matlab)

In this problem, write the first of two functions. This first function takes in the first and last name and returns a string that is lastname_firstname and with any dashes (-) in the name taken out.

Note that youll be testing it by calling it from the command line; youll call it from a script in problem 3.

Deliverables:

Function file that takes in a string and returns a string without a dash

Call that function from the command line and show that it works

strNoDash = RemoveDash(first-dash);

Function file that takes in first and last name and returns the joined name

Call the function from the command line and show that it works

str = JoinName(first, last)

str = JoinName(first, last-dash);

str = JoinName(first-dash, last-dash);

Step by Step Instructions:

Create a function file. It should take in two variables and return one.

Start with using strcat or sprintf to join the names together. Check that it works with first and last (call from the command line)

Note: One trick is to copy the first line of the function file, delete the function key word, and then put your own variable values in. This makes sure that you have the inputs and the outputs in the right order

I.e., copy function function [strOut] = JoinNames( strFirst, strLast ) to the command line,

and then edit to be

strOut = JoinNames(first, last)

Now add code to your function to check for the dash (-) in either the first or last name

Try strfind(first). What do you get?

try strfind(first-dash). What do you get?

Youll need isempty to check for an empty return

If you have a dash, you need to delete it. Theres two ways to do this. Either set that element to the empty array

array(k) = [] - deletes the kth element from array

array = strcat( array(1:k-1), array(k+1:end) ) set the array to the first and second halves

Make another function that takes in a string and returns the same string with no dashes. Call this on both inputs from within your join string function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions