Question

In: Computer Science

In matlab please. It says that not enough arguments. How, what, and where to input? function...

In matlab please. It says that not enough arguments. How, what, and where to input?

function longestword (word1,word2,word3)
if strlength(word1) > strlength(word2) && strlength(word1) > strlength(word3)
fprintf(word1);
elseif strlength(word2) > strlength(word1) && strlength(word2) > strlength(word3)
fprintf(word2);
else
fprintf(word3)
end
end

Solutions

Expert Solution

Actually, your function longestword defines 3 input arguments (word1, word2, word3). So,once you have your longestword function defined, you need to call it in order to run the function. For example, if you call and run your longestword function in the command window without specifying any arguments like this:

longestword

then you will be getting the error "Not enough input arguments".

So basically when you have the file "longestword.m" open in the Editor, and you try to run the function by pressing the F5 or the "Run" button, MATLAB then runs the longestword function without any input arguments, and hence you get the error "Not enough input arguments". Then after this, the "Run" button dropdown menu opens up for you automatically, prompting you to enter the missing values for input arguments. There you can put your desired values and hit enter to run the function. Also, if you want to change the values of different words, you can again press the down arrow below the "Run" button and enter new values.

HOW TO FIX THE ERROR: So now when you have understood the basic reason of error, all you have to do is just call and run the longestword function with specifying 3 input arguments, "word1", "word2", and "word3" as given below (assuming that the arguments "word1", "word2", and "word3" are defined):

longestword(word1, word2, word3)

then you will not get the error message.

For your better and easy understanding, I have provided the full Matlab code for your function, so that you can run it successfully on your Matlab. The code for your longestword function is as given below:

%define variables word1, word2, and word3 before using them in our longestword function

word1 = input('Enter word 1:', 's') %define whatever string value you like for word1
word2 = input('Enter word 2:', 's') %define whatever string value you like for word2
word3 = input('Enter word 3:', 's') %define whatever string value you like for word3

%your actually defined longestword function

function longestword (word1,word2,word3)
if strlength(word1) > strlength(word2) && strlength(word1) > strlength(word3)
fprintf(word1);
elseif strlength(word2) > strlength(word1) && strlength(word2) > strlength(word3)
fprintf(word2);
else
fprintf(word3)
end
end

%avoiding and fixing the error

longestword(word1, word2, word3); %here we need to and are CALLING longestword function with three input arguments word1, word2, and word3 as defined before to avoid the Error that you are facing.

Note that I have also included comments for your easy understanding. Just read them carefully and follow the steps to avoid any errors.

Thanks!


Related Solutions

Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
In python can you fix the error in the line where it says message = input("Input...
In python can you fix the error in the line where it says message = input("Input a lowercase sentence: ") this is the error message I get after running the program and inputing a lowercase sentence Input a lowercase sentence:hello hi MM§MTraceback (most recent call last): MM§M File "client.py", line 14, in <module> MM§M message = input("Input a lowercase sentence:") MM§M File "<string>", line 1 MM§M hello hi MM§M ^ MM§MSyntaxError: unexpected EOF while parsing from socket import * #...
Write a function that will receive two input arguments that is the height in inches (in.)...
Write a function that will receive two input arguments that is the height in inches (in.) and the weight in pounds (lb) of a person and return two output arguments that is the height in meters (m) and mass in kilograms (kg). Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. Determine your own height and weight in SI units. Note: 1 meter = 39.3701 inch, 1 foot = 12 inches,...
write a matlab function for frequency analysis using DFT. the function should take as input a...
write a matlab function for frequency analysis using DFT. the function should take as input a signal, and as output the number of sinusoids and their frequencies.
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
Assume there is a function called frustumArea that has three input arguments and returns the area...
Assume there is a function called frustumArea that has three input arguments and returns the area of a frustum: area = frustumArea( height, majRadius, minRadius ). When the major and minor radii of a frustum are equal, the frustum is a cylinder. Write a new function named cylinderArea that uses the frustumArea function to compute and return the area of a cylinder. Do this for both Python and Matlab.
Use SVD method to compress and decompress images in the MATLAB. Compression function. The input is...
Use SVD method to compress and decompress images in the MATLAB. Compression function. The input is an image file and k. The output is a text file containing the reduced U, V , and the reduced diagonals of ?. Decompression function. The input is the output of the compression code. The output is an image (you can use imshow for this purpose).
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Using Matlab, write a function that takes numeric data as its input argument and prints a...
Using Matlab, write a function that takes numeric data as its input argument and prints a message to the Command Window stating if the number is positive, or negative, or 0. This function should transfer an output value to the Workspace ONLY when the input value is negative. Please include a copiable code and the associated screenshots.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT