Question

This question is for MATLAB. Write a script that continuously asks the user for a new...

This question is for MATLAB.

Write a script that continuously asks the user for a new sentence, until the user
types the word "STOP". The program records all of the sentences the user wrote
(not including "STOP") in a matrix with as many rows as needed but with an N
number of columns. The user is prompted to provide N before typing in the first
sentence.
The output of the program is the array with the sentences in it, in two forms: the
array in numbers corresponding to letters, and the array in letters. (hint: in class
we discussed the commands "char" and "double"). Please submit a working code
and nothing else.

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

CODE :

N=input('What is N? ');
i=1;
line='';
sen=input('next sentence: ','s');
while ~strcmp(sen,'STOP')
line=[line,sen];
if length(line)>=N
wordarray(i,:)=line(1:N);
line=line(N+1:end);
i=i+1;
end
sen=input('next sentence: ','s');
end
parag=double(wordarray)
wordarray

OUTPUT :

>> wordArray_N What is N? 15 next sentence: Are We clear?? next sentence: Yes Sir! next sentence: ARE WE CLEAR??! next senten

Add a comment
Know the answer?
Add Answer to:
This question is for MATLAB. Write a script that continuously asks the user for a new...
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
  • USING MATLAB Write a script that asks the user to input a sentence. It then replaces...

    USING MATLAB Write a script that asks the user to input a sentence. It then replaces all instance of 'he', 'she', 'He', or 'She' with 'Mr. Meseeks' and prints out the new sentence. . HINT: Use 'strrep' and 'lower' function.

  • Write a MATLAB script that asks the user to enter a whole number (i.e., any whole...

    Write a MATLAB script that asks the user to enter a whole number (i.e., any whole number, positive, negative or zero). After the number is entered, the program must utilize an IF-ELSE statement and determine the parity of the number. The parity of a number is simply whether it is an even number or an odd number. If the number is even, MATLAB must then generate and display the message: The entered number is an even number. Otherwise, MATLAB must...

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • In Matlab, write a script which asks a user to input numbers until the user inputs...

    In Matlab, write a script which asks a user to input numbers until the user inputs 0. Then the script should print only the positive numbers entered by the user, in reverse order. For example, if the user inputs “4,-1,5,2,-3,-8,0” the script should print “2,5,4”.

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • Write a Matlab script that asks the user for two angles in degrees and stores them...

    Write a Matlab script that asks the user for two angles in degrees and stores them as variables. Calculate and store the cosines of the numbers (they must be converted to radians to use Matlab's cos function). Use a conditional statement and fprintf to print the larger of the two cosine values and the angle (in degrees) that resulted in that value. If they are equal, print a message to the effect that the cosines of the two angles (print...

  • Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...

    Modular program mathlab: Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “You got it” If the user’s die is smaller, it should display, “Nice try” If the results are the...

  • In java, write a program with a recursive method which asks the user for a text...

    In java, write a program with a recursive method which asks the user for a text file (verifying that the text file exists and is readable) and opens the file and for each word in the file determines if the word only contains characters and determines if the word is alpha opposite. Now what I mean by alpha opposite is that each letter is the word is opposite from the other letter in the alphabet. For example take the word...

  • Please show in MATLAB code using if and else statements if necessary Write a program in a script ...

    Please show in MATLAB code using if and else statements if necessary Write a program in a script file that converts a quantity of energy given in units of either J (Joules), Btu, or (ft-lb) to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of power in the new units using the fprintf command....

  • I matlab, write a script that obtains user input, and displays the answer to a question...

    I matlab, write a script that obtains user input, and displays the answer to a question Write a program that uses the input function to ask a user for a depth of snow, and area of a rooftop. Let's assume that the density of snow is 100 kg/m3 (feel free to play around with this as another user input). Output to the screen a message telling the user the total weight of the snow (in kg) on their roof.

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