Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to interpret strings

Subject: How to interpret strings

From: Diego Zegarra

Date: 24 Mar, 2009 03:38:01

Message: 1 of 2

I am getting the filenames for some problems having the following format,

'**on**Rp30Rs70_**.dat'
'**on**Rp50Rs50_**.dat'
'**on**Rp70Rs30_**.dat'

I need to make a decision based on which of these 3 formats it has,

if '**on**Rp30Rs70_**.dat'
    do this
else if '**on**Rp50Rs50_**.dat'
    do this
else
    do this
end

Thanks for the help!

Subject: How to interpret strings

From: us

Date: 24 Mar, 2009 08:50:17

Message: 2 of 2

"Diego Zegarra"
> I am getting the filenames for some problems having the following format,
> '**on**Rp30Rs70_**.dat'
> I need to make a decision based on which of these 3 formats it has,
> if '**on**Rp30Rs70_**.dat'
> do this

one of the solutions

% the data
% - a list of file names
     flst={
          'fooongooRp20Rs70_123.dat'
          'fooongooRp30Rs70_123.dat'
          'fooongooRp40Rs70_123.dat'
          'fooonGOORp30Rs70_123.dat'
     };
% - a template
     tmpl={
          '.+on.+Rp30Rs70\_.+\.dat' % <- eg, '**on**Rp30Rs70_**.dat'
     };
% the engine
     r=regexp(flst,tmpl{1});
     r=~cellfun(@isempty,r);
     r=flst(r);
% the result
     disp(r);
%{
          'fooongooRp30Rs70_123.dat'
          'fooonGOORp30Rs70_123.dat'
%}
% use the logical R in your loop...

us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us