How to find n letter strings in an array
Show older comments
I have created an array of strings with more than 1000 words and i am trying to find 2 letter strings in that array. How do i check every string if they have only 2 words and how to print them individually.
3 Comments
It is not clear to me what you are trying to do. Here is my best guess. Your input is something like
in = ["MATLAB rocks", "MATLAB is fun", "MATLAB rules"]
Only the first and third elements of that array have exactly two words, so you want your output to be
out = ["MATLAB rocks", "MATLAB rules"]
Is that right? If not, it would be very helpful if you could create a small example of the input and expected output.
Onur Murat
on 9 Aug 2021
John D'Errico
on 9 Aug 2021
Edited: John D'Errico
on 9 Aug 2021
MATLAB does not have a print command, at least not to print data to the command window. (MATLAB's print will try to print a figure to your printer. Are you still programming in python?
Answers (1)
X = ["in", "out", "go", "come"];
output = X(strlength(X)==2)
The print command is for figures, so I'm not sure what you mean by "print command for output". What I wrote above will display to the screen. Do you mean you want to write the output to an external file?
Categories
Find more on Characters and Strings 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!