2

I have the following code:

fonts = dir('fonts')

strcmp('BELL.TTF',fonts.name)

where dir('fonts') returns a 33x1 struct where each entry has name (string), date, and a few other things. I can't figure out what type fonts.name is (if it's a cell array or what), and my end goal is to be able to use strcmp to compare across all of the names.

4

1 回答 1

4

fonts.name is 33 separate character arrays. You want to combine these into a cell array so that you can use it with strcmp.

In code:

fonts = dir('fonts');
%# use curly brackets to combine the 33 strings into a cell array
tf = strcmp('BELL.TTF',{fonts.name})

tf is a logical array with 1 wherever fonts.name is equal to 'BELL.TTF'

于 2010-12-05T04:01:28.830 回答