I need extreme help on a lab for my CSCE155N course which is MatLab. Please help
ID: 3679335 • Letter: I
Question
I need extreme help on a lab for my CSCE155N course which is MatLab. Please help with the following files.
-Modify randomSentence.m so that the function returns words that can form a random sentence that is generated from banks of names, verbs, and nouns
-The banks will be stored as cell arrays of string
This file below is randomSentence.m:
Example:
>> for i = 1 : 5
randomSentence
end
ans =
'Stewart' 'milks' 'bicycles'
-Modify printRecord.m so that the function returns a string that displays information about the record
-The record will be provided as a cell array
-Use sprintf
This is the file of printRecord.m:
Example:
>> record = { 0 , Ryan , 43 }
record =
[0] Ryan [43]
>> printRecord( record )
ans =
Ryan (ID: 0): 43 points
-Modify printInfo.m so that the function returns a cell array of strings that reports the names, heights, and nal weights of the provided experiment subjects
-The subjects' information will be provided in an array of structures
-Use sprintf
This file is printInfo.m:
Example:
>> subjects.name = Ryan ;
subjects.id = 0;
subjects.weight = [ 134 145 ];
subjects.height.feet = 6;
subjects.height.inches = 0;
for s = 2 : 4
subjects( s ).name = char( randi( 26 , 1 , randi( 10 ) ) + 96 );
subjects( s ).id = randi( 100 );
subjects( s ).weight = randi( 100 , 1 , 2 ) + 100;
subjects( s ).height.feet = randi( 4 ) + 3;
subjects( s ).height.inches = randi( 12 ) - 1;
end
>> printInfo( subjects );
>> ans
ans =
Ryan: 6' 0", 145 pounds
l: 4 5", 180 pounds
qsthr: 5' 11", 112 pounds'
pftg: 7' 6", 190 pounds'
Explanation / Answer
Examples
Generate a random DNA sequence.
randseq(20)
ans =
TAGCTGGCCAAGCGAGCTTG
Generate a random RNA sequence.
randseq(20,'alphabet','rna')
ans =
GCUGCGGCGGUUGUAUCCUG
Generate a random protein sequence.
randseq(20,'alphabet','amino')
ans =
DYKMCLYEFGMFGHFTGHKK
Create a character vector that includes a single quote.
msg = 'You''re right!'
msg =
You're right!
Create the character vector name using two methods of concatenation.
name = ['Thomas' ' R. ' 'Lee']
name = strcat('Thomas',' R.',' Lee')
Create a character array.
C = char('Hello','Goodbye','Yes','No')
C =
Hello
Goodbye
Yes
No
Create a cell array of character vectors.
S = {'Hello' 'Goodbye'; 'Yes' 'No'}
S =
'Hello' 'Goodbye'
'Yes' 'No'
Example for writing functions-
Create a function file, named mymax.m and type the following code in it –
function max = mymax(n1, n2, n3, n4, n5)
%This function calculates the maximum of the
% five numbers given as input
max = n1;
if(n2 > max)
max = n2;
end
if(n3 > max)
max = n3;
end
if(n4 > max)
max = n4;
end
if(n5 > max)
max = n5;
end
MATLAB will execute the above statement and return the following result
This function calculates the maximum of the
five numbers given as input
You can call the function as
mymax(34, 78, 89, 23, 11)
MATLAB will execute the above statement and return the following result
ans = 89
Create a script file and type the following code into it
name = 'Zara Ali ';
position = 'Sr. Surgeon ';
worksAt = 'R N Tagore Cardiology Research Center';
profile = [name ', ' position ', ' worksAt]
profile = strcat(name, ', ', position, ', ', worksAt)
When you run the file, it displays the following result
profile = Zara Ali, Sr. Surgeon, R N Tagore Cardiology Research Center
profile = Zara Ali,Sr. Surgeon,R N Tagore Cardiology Research Center
Combining Strings into a Cell Array
The cellstr function converts a character array into a cell array of strings.
Example
Create a script file and type the following code into it
name = 'Zara Ali ';
position = 'Sr. Surgeon ';
worksAt = 'R N Tagore Cardiology Research Center';
profile = char(name, position, worksAt);
profile = cellstr(profile);
disp(profile)
When you run the file, it displays the following result
{
[1,1] = Zara Ali
[2,1] = Sr. Surgeon
[3,1] = R N Tagore Cardiology Research Center
}
Create a script file and type the following code into it
students = {'Zara Ali', 'Neha Bhatnagar', ...
'Monica Malik', 'Madhu Gautam', ...
'Madhu Sharma', 'Bhawna Sharma',...
'Nuha Ali', 'Reva Dutta', ...
'Sunaina Ali', 'Sofia Kabir'};
% The strrep function searches and replaces sub-string.
new_student = strrep(students(8), 'Reva', 'Poulomi')
% Display first names
first_names = strtok(students)
When you run the file, it displays the following result
new_student =
{
[1,1] = Poulomi Dutta
}
first_names =
{
[1,1] = Zara
[1,2] = Neha
[1,3] = Monica
[1,4] = Madhu
[1,5] = Madhu
[1,6] = Bhawna
[1,7] = Nuha
[1,8] = Reva
[1,9] = Sunaina
[1,10] = Sofia
}
Following table provides brief description of the string functions in MATLAB
Function
Purpose
Functions for storing text in character arrays, combine character arrays, etc.
blanks
Create string of blank characters
cellstr
Create cell array of strings from character array
char
Convert to character array (string)
iscellstr
Determine whether input is cell array of strings
ischar
Determine whether item is character array
sprintf
Format data into string
strcat
Concatenate strings horizontally
strjoin
Join strings in cell array into single string
Functions for identifying parts of strings, find and replace substrings
ischar
Determine whether item is character array
isletter
Array elements that are alphabetic letters
isspace
Array elements that are space characters
isstrprop
Determine whether string is of specified category
sscanf
Read formatted data from string
strfind
Find one string within another
strrep
Find and replace substring
strsplit
Split string at specified delimiter
strtok
Selected parts of string
validatestring
Check validity of text string
symvar
Determine symbolic variables in expression
regexp
Match regular expression (case sensitive)
regexpi
Match regular expression (case insensitive)
regexprep
Replace string using regular expression
regexptranslate
Translate string into regular expression
Functions for string comparison
strcmp
Compare strings (case sensitive)
strcmpi
Compare strings (case insensitive)
strncmp
Compare first n characters of strings (case sensitive)
strncmpi
Compare first n characters of strings (case insensitive)
Functions for changing string to upper- or lowercase, creating or removing white space
deblank
Strip trailing blanks from end of string
strtrim
Remove leading and trailing white space from string
lower
Convert string to lowercase
upper
Convert string to uppercase
strjust
Justify character array
Note- With the help of above function examples/syntax the given problem can be solved.
Function
Purpose
Functions for storing text in character arrays, combine character arrays, etc.
blanks
Create string of blank characters
cellstr
Create cell array of strings from character array
char
Convert to character array (string)
iscellstr
Determine whether input is cell array of strings
ischar
Determine whether item is character array
sprintf
Format data into string
strcat
Concatenate strings horizontally
strjoin
Join strings in cell array into single string
Functions for identifying parts of strings, find and replace substrings
ischar
Determine whether item is character array
isletter
Array elements that are alphabetic letters
isspace
Array elements that are space characters
isstrprop
Determine whether string is of specified category
sscanf
Read formatted data from string
strfind
Find one string within another
strrep
Find and replace substring
strsplit
Split string at specified delimiter
strtok
Selected parts of string
validatestring
Check validity of text string
symvar
Determine symbolic variables in expression
regexp
Match regular expression (case sensitive)
regexpi
Match regular expression (case insensitive)
regexprep
Replace string using regular expression
regexptranslate
Translate string into regular expression
Functions for string comparison
strcmp
Compare strings (case sensitive)
strcmpi
Compare strings (case insensitive)
strncmp
Compare first n characters of strings (case sensitive)
strncmpi
Compare first n characters of strings (case insensitive)
Functions for changing string to upper- or lowercase, creating or removing white space
deblank
Strip trailing blanks from end of string
strtrim
Remove leading and trailing white space from string
lower
Convert string to lowercase
upper
Convert string to uppercase
strjust
Justify character array
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.