0

I am new to programming and i start with Matlab. How to convert this expression to a MATLAB code :

a = if !IsNaN(x) then b else Double.NaN;
A.ben
  • 13
  • 2
  • Are you stuck on the ternary part? [It looks like Matlab doesn't have that](https://stackoverflow.com/questions/5594937/ternary-operator-in-matlab): you may have to split this out into the NaN check on x and two separate assignments of a. Or are you stuck on something else? – Rup Apr 27 '18 at 20:16
  • @Rup : I stuck on NaN and Double.NaN – A.ben Apr 27 '18 at 21:08

1 Answers1

2

The "not" functionality of "!" is implemented by "~" in MATLAB.

So, your code would look something like

if ~isnan(x)
   a = b
else 
   a = NaN;
end
Vahni
  • 272
  • 1
  • 10