lab1 ex3
You cannot submit for this problem because the homework's deadline is due.
Ex3. Operations on strings (10 marks)
Tip: strings vs. char arrays in MATLAB
In MATLAB, "abc"
is actually different from 'abc'
. Rigorously speaking, only the former is called a string. The latter is called a char array. However, strings were not introduced until MATLAB R2016b (quite late!) and most built-in functions still expect char arrays instead of strings as parameters. Thus, generally, please always use 'abc'
instead of "abc"
. For more information about strings, see doc string
. In VG101 labs, we mean char arrays when we say strings.
Ex3_1. Conversion
Get a number represented as a string from user input using input('', 's')
(notice the second parameter 's'
) and convert the string to a number.
Hint: Use str2num()
. See its documentation and pay attention to the format requirements. Also read the note on the documentation page.
Sample Test Cases
Input:
123.4
Output:
123.4000
Input:
wtcl555
Output:
Ex3_2. String concatenation
Concatenate two strings s1
and s2
obtained from user input.
Hint: You can either use strcat()
or regard the strings as arrays. Please solve the problem using both ways.
Sample Test Case
Input:
wtcl
555
Output:
wtcl555
wtcl555
Lab 1 exercises
- Status
- Finished
- Problems
- 3
- Open Since
- 2023-05-17 18:15
- DDL
- 2023-05-18 00:00
- Extension
- 48.0 hour(s)