Finding a letter or number in a string of cells
4 views (last 30 days)
Show older comments
Example. Say I have a cell array = Brad1, Bobby2, 1Bob, 2Bradley, 2Bailey. etc... Each Name is a file of information containing some attributes. Say this cell array of names is about 180 files long.
I need to separate the names, i.e put them in either a cell array for names that contain a 1, or place them into an array if their name contains a 2. How would I do this using a for loop?.
0 Comments
Answers (3)
TastyPastry
on 29 Oct 2015
out = {};
for i=1:numel(myData)
myStr = myData{i};
myNum = str2double(myStr(myStr>= 48 & myStr <= 57));
myName = myStr(isstrprop(myStr,'alpha'));
out{size(out,1)+1,myNum} = myName;
end
This stores the data into a cell array where the columns correspond to the values in the names.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!