Challenge - 5 Problems
String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of strcmp with different cases
What is the output of this MATLAB code snippet?
MATLAB
result = strcmp('Hello', 'hello'); disp(result);
Attempts:
2 left
💡 Hint
strcmp is case-sensitive and returns 1 if strings match exactly.
✗ Incorrect
strcmp compares two strings exactly, including case. 'Hello' and 'hello' differ in case, so strcmp returns 0.
❓ Predict Output
intermediate2:00remaining
Using strcmpi for case-insensitive comparison
What will this MATLAB code display?
MATLAB
result = strcmpi('MATLAB', 'matlab'); disp(result);
Attempts:
2 left
💡 Hint
strcmpi compares strings ignoring case differences.
✗ Incorrect
strcmpi returns 1 because it ignores case and the strings match.
❓ Predict Output
advanced2: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);Attempts:
2 left
💡 Hint
strcmp compares each pair of strings element-wise and is case-sensitive.
✗ Incorrect
The second elements differ in case ('dog' vs 'Dog'), so strcmp returns 0 for that element.
❓ Predict Output
advanced2:00remaining
Behavior of isequal with strings
What does this MATLAB code print?
MATLAB
str1 = 'Test'; str2 = 'test'; result = isequal(str1, str2); disp(result);
Attempts:
2 left
💡 Hint
isequal compares values exactly, including case.
✗ Incorrect
isequal returns 0 because 'Test' and 'test' differ in case.
🧠 Conceptual
expert2:00remaining
Understanding strcmp return values
Which option correctly describes the return value of strcmp when comparing two strings in MATLAB?
Attempts:
2 left
💡 Hint
Think about what strcmp returns when strings match exactly.
✗ Incorrect
strcmp returns logical 1 (true) if strings match exactly, else logical 0 (false). It does not return counts or ASCII differences.