Matlab Lab, Check answers and need some help

Thread Starter

Judas543

Joined Jan 26, 2010
60
Copy separate into a new .m file

If someone could check over this and help me with the needed parts then that would be great. It's due before 10 PM EST




#1) Write a Matlab function that takes a string(short sentence) as its input and returns a string where all the occurrences of "blanks" are replaced with "-". The function is then be used in a script asking the user to enter a short sentence, and then displays the modified string.

Main Script

clc %clear command
clear %clear workspace


myString = input('Type a sentence (between single quotes):'); %Input Sentence
[Blank] = replace(myString);


Function Script
function Blank = blank1(myString)
for Blank = 1:length(myString)
if myString(Blank) == '-'; %If myString has a space then replace with (-)
myString(Blank) = ' '
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


2) Write a function that returns the positions of the "blank spaces" in a sentence entered by the user.
%For this one I just kept the same input and change the "-" and replace with " ".

However is there another way of doing this if the two questions are independent?



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

3)Enter your name. The matlab script displays your name spelled backwards.
Ex: user types in john
returns john
Hello nhoj

clear
clc

%
myName = input('What is your name (between single quotes):'); %e.g Input mike
fliplr (myName)

%I used fliplr built in function.. However I would like to know how to do it without the built in function.. You can do it with the for loop but i need help finishing it up...

for k = length(myName):-1:1
%something like newName(k) = myName(k-1) dunno Please help
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

4)Write a matlab script that asks the user to enter a noun, and the program displays: "the plural of noun_entered is: noun_entereds"

clc
clear

noun = input('Please enter a noun (between single quotes):') %Input a Noun
Nplural = [noun,'s'] %Adds a 's' to your noun
fprintf('The plural of your noun is %s \n',Nplural) %Print Result

%However i want it to say the plural of the word is words... With script for #4 is there a way to do that?


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

5)Write a function that soncerts to uppercase all the letters of a word(assumed to be entered in lowercase)

This is easily done with upper built in function but is there a way to do it another way. My professor gave us a hint and said look at an ASCII table
 
Top