0
0
MATLABdata~20 mins

String comparison in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of strcmp with different cases
What is the output of this MATLAB code snippet?
MATLAB
result = strcmp('Hello', 'hello');
disp(result);
AError: Undefined function or variable 'strcmp'.
B1
C0
D2
Attempts:
2 left
💡 Hint
strcmp is case-sensitive and returns 1 if strings match exactly.
Predict Output
intermediate
2:00remaining
Using strcmpi for case-insensitive comparison
What will this MATLAB code display?
MATLAB
result = strcmpi('MATLAB', 'matlab');
disp(result);
A1
BError: Undefined function or variable 'strcmpi'.
C0
DNaN
Attempts:
2 left
💡 Hint
strcmpi compares strings ignoring case differences.
Predict Output
advanced
2:00remaining
Comparing string arrays with strcmp
What is the output of this code?
MATLAB
A = {'cat', 'dog', 'bird'};
B = {'cat', 'Dog', 'bird'};
result = strcmp(A, B);
disp(result);
A[1 0 1]
B[1 1 1]
C[0 0 0]
DError: Cell contents reference from a non-cell array object.
Attempts:
2 left
💡 Hint
strcmp compares each pair of strings element-wise and is case-sensitive.
Predict Output
advanced
2:00remaining
Behavior of isequal with strings
What does this MATLAB code print?
MATLAB
str1 = 'Test';
str2 = 'test';
result = isequal(str1, str2);
disp(result);
A1
B0
CError: Undefined function or variable 'isequal'.
DNaN
Attempts:
2 left
💡 Hint
isequal compares values exactly, including case.
🧠 Conceptual
expert
2:00remaining
Understanding strcmp return values
Which option correctly describes the return value of strcmp when comparing two strings in MATLAB?
AIt returns a string 'true' or 'false' depending on the comparison.
BIt returns the number of matching characters at the start of the strings.
CIt returns the ASCII difference between the first non-matching characters.
DIt returns a logical 1 if the strings are exactly the same, otherwise logical 0.
Attempts:
2 left
💡 Hint
Think about what strcmp returns when strings match exactly.