MATLAB selecting items considering the end of their name

57 views Asked by At

I have to extract the onset times for a fMRI experiment. I have a nested output called "ResOut", which contains different matrices. One of these is called "cond", and I need the 4th element of it [1,2,3,4]. But I need to know its onset time just when the items in "pict" matrix (inside ResOut file) have a name that ends with "*v.JPG". Here's the part of the code that I wrote (but it's not working):

for i=1:length(ResOut); 
    if ResOut(i).cond(4)==1 && ResOut(i).pict== endsWith(*"v.JPG")

What's wrong? Can you halp me to fix it out? Thank you in advance,

Adriano

1

There are 1 answers

0
sco1 On

It's generally helpful to start with unfamiliar functions by reading their documentation to understand what inputs they are expecting. Per the documentation for endsWith, it expects two inputs: the input text and the pattern to match. In your example, you are only passing it one (incorrectly formatted) string input, so it's going to error out.

To fix this, call the function properly. For example:

filepath = ["./Some Path/mazeltov.jpg"; "~/Some Path/myfile.jpg"];
test = endsWith(filepath, 'v.jpg')

Returns:

test =

  2×1 logical array

   1
   0

Or, more specifically to your code snippet:

endsWith(ResOut(i).pict, 'v.JPG')

Note that there is an optional third input, 'IgnoreCase', which you can pass as a boolean true/false to control whether or not the matching ignores case.