how to find number of substring in a string in matlab

You can use the count function in MATLAB to count the number of occurrences of a substring in a string. Here's an example:

main.m
str = 'This is a string.';
substr = 'is';
count = numel(strfind(str, substr));
disp(count); % Output: 2
104 chars
5 lines

In this example, we first create a string str. We want to count the number of occurrences of the substring 'is' in str. To do this, we use the strfind function to find all occurrences of 'is' in str. We then use the numel function to count the number of occurrences found by strfind. The resulting count is stored in the variable count. Finally, we use the disp function to display the count on the command window.

gistlibby LogSnag