Bird
0
0

You want to compare two cell arrays of strings c1 = {'cat', 'dog'} and c2 = {'Cat', 'dog'} ignoring case. Which MATLAB code correctly returns a logical array indicating matches?

hard📝 Application Q8 of 15
MATLAB - String Handling
You want to compare two cell arrays of strings c1 = {'cat', 'dog'} and c2 = {'Cat', 'dog'} ignoring case. Which MATLAB code correctly returns a logical array indicating matches?
Acellfun(@strcmpi, c1, c2)
Bstrcmpi(c1, c2)
Carrayfun(@strcmpi, c1, c2)
Dstrcmp(c1, c2)
Step-by-Step Solution
Solution:
  1. Step 1: Understand cell array string comparison

    strcmpi does not directly compare cell arrays element-wise.
  2. Step 2: Use arrayfun with strcmpi for element-wise comparison

    arrayfun(@strcmpi, c1, c2) applies strcmpi to each pair of elements, returning logical array.
  3. Final Answer:

    arrayfun(@strcmpi, c1, c2) -> Option C
  4. Quick Check:

    Use arrayfun with strcmpi for cell array comparison [OK]
Quick Trick: Use arrayfun(@strcmpi, c1, c2) for cell array string comparison [OK]
Common Mistakes:
  • Using cellfun instead of arrayfun
  • Calling strcmpi directly on cell arrays
  • Using strcmp instead of strcmpi

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes