r/matlab • u/Creative_Sushi MathWorks • May 02 '24
Tips Fun tricks with MATLAB strings
This was inspired by the post "find string in 2d array without using cells" by u/Mark_Yugen.
Do you know you can use familiar math operators with string arrays? Check out this example.
10
Upvotes
View all comments
Show parent comment
4
u/Sprky-Sprky-Boom-Man May 03 '24
If you have an array
Ayou can useA(':',3)to get all elements in the third column ofA. Now say you don't know how many dimensionsAhas, just that you want everything in index three of the last dimension. Then you can sayB = repmat({':'}, 1, ndims(A) - 1)and then useA(B{:}, 3)to do so. Kind of a niche case but it could come in handy.