IF statement inside a function called via rowfun.

I have some timetables in which I want to apply a function in which the following code is written:
Z = 182.13;
if any(Re_h > Z, 'all')
psi_h = (Re_h ./ Z).^(-0.15.*sind(57.6));
elseif any(Re_h < Z, 'all')
psi_h = 1;
end
the problem I am facing is that I don't understand why it never enters the elseif statement although the Re_h is less than Z. No matter which value the Re_h is that it will execute the first statement.
I first tried this way but did not work as well:
if Re_h > Z
psi_h = (Re_h ./ Z).^(-0.15.*sind(57.6));
else
psi_h = 1;
end
I think the problem might be with the table row execution I think, but I don't know how to do it and I wondered if somebody could help me.
Thanks.

3 Comments

might be better if you share a sample data set. Did you pass a group parameter when you did the rowfun as well? If you did, then Re_h might be a vector. So have you checked if any of its value is larger than Z so that it never triggers the elseif block. If Re_h never be a matrix, then the 'all' option is prob useless i think. So it depends on what Re_h actually is.
Hi Roger,
I believe that the variable Re_h is important to solving the issue you're facing. As mentioned by @Peng, sharing the code that you use to get the of value(s) of Re_h might be helpful to solve the issue.
Further, even if at least one of the values of the vector Re_h is a value greater than z, the first block of your code fails. Next, the second block of your code failing indicates that all the element(s) within Re_h are in greater than z. This is a peculiar case.
Roger, you need to show a small example of what your timetable looks like (as others have said), as well as the entire function you are applying, as well as the call to rowfun. Noone can help you with those.

Sign in to comment.

Answers (0)

Products

Release

R2019b

Asked:

on 14 Apr 2020

Commented:

on 27 Apr 2020

Community Treasure Hunt

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

Start Hunting!