How to find n letter strings in an array

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"]
in = 1×3 string array
"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"]
out = 1×2 string array
"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.
I've tried to mean 2 letter words like i am trying to find 2 letter words in, X=["in", "out", "go", "come"] to give me output "in" and "go" since they are made of 2 letters but X has more than 1 thousand words in it and i would really appreciate if you could use print command for output or anything like it.
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?

Sign in to comment.

Answers (1)

X = ["in", "out", "go", "come"];
output = X(strlength(X)==2)
output = 1×2 string array
"in" "go"
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

Asked:

on 9 Aug 2021

Edited:

on 9 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!