IF.. condition with cellfund and strfind terms integrated

2 views (last 30 days)
Hi guys,
I got a problem with one of my if... statements and i hope u can help me. Probably this one is really simple, but i can't figure it out.
I try to to compare strings with the strfind() method to get the ones I searched for. That does work very well, even if I use the cellfun('isempty') methode to get all entries which are empty. My problem now is, that if I use my cellfun('isempty',...) methode in my if ... statement, it returns for eatch entry that it is empty. I tried another solution, by using the any() methode, cause i thought matlab do have a problem, with two entries in an if.. statement, but it didn't work either.
Here are the given conditions: ______________________________________________________________________
handles.Rad_kreuz = {'Radiation_05_Aug_01to03_2012_kreuz',
'Radiation_05_Aug_22to31_2012_kreuz'};
handles.month_data = {'Jan';'Feb';'Mar';...;'Aug';...};
if cellfun('isempty',strfind(Rad_kreuz,handles.month_data{i,1}))...
_______________________________________________________________________
So if someone can help me, i would appreciate it a lot.
Thank you.
  3 Comments
Johan
Johan on 7 Feb 2013
Hi Jan Simon,
"i" is my variable for the for... methode I use to switch trough my handles.month_data. I didn't get an error message, but now I also know why :).
I just figured out the problem myself, I used "i" as my for variable, allthough i should have used "j". Sometimes these simple mistakes are causing so much trouble. Damn, that was really a stupid question now.
But nevertheless, thank you.
Jan
Jan on 7 Feb 2013
I'm glad that you could solve the problem. Using "i" and "j" as loop counters is prone to errors due to a confusion with the imaginary unit. A speaking name as iMonth is rarely confused by something else. At first it looks less compact, but who cares when it saves hours of tedious debugging time?

Sign in to comment.

Answers (1)

Jan
Jan on 7 Feb 2013
Rad_kreuz = {'Radiation_05_Aug_01to03_2012_kreuz',
'Radiation_05_Aug_22to31_2012_kreuz'};
month_data = {'Jan';'Feb';'Mar';...;'Aug';...};
cellfun('isempty', strfind(Rad_kreuz, month_data{1}))
I expect the reply [true, true], because bother strings do not contain the substring 'Jan'. If the IF gets a vector as input, it performs an all(Condition) & ~isempty(Condition) implicitly. To avoid confusions, I would insert the all() explicitly.
cellfun('isempty', strfind(Rad_kreuz, month_data{8}))
Expected reply: [false, false].
Then what is the problem with these values?

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!