How can I determine whether a string contains a substring?

Alan Garger · Dec 27, 2023 · 2.3K views
Question
I have directory names that end in '0.0100'. I want to be able to skip certain directories by comparing the substring '0.0100' to the directory name. How can I do this?  
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 13, 2026
You can use the 'contains' function to determine whether a string contains a given substring or not. Specifically, 'contains' returns true if the first argument contains the second argument and false otherwise. For example:
 
 
>> smallSubstring = '0.0100';
>> largeString1 = 'Item0.0100';
>> largeString2 = 'Item0.0101';
>> contains(largeString1, smallSubstring)

ans =

  logical

   1

>> contains(largeString2, smallSubstring)

ans =

  logical

   0

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!