From: Walter Roberson on 16 Feb 2010 23:22 Nick N wrote: > Dear all, > > I am new to this forum & Matlab. Just wondering if Matlab supports this kind of statement like in C programming: > > (expr1) ? expr2:expr3 > > This is equivalent to > if (expr1) > expr2; > else > exp3; > end; Actually, that C operator is not exactly equivalent to that sequence of if/else statements. C has some complexities having to do with the type of the expression, so there can be some implicit type-casting going on that is not accounted for in your if/else version. In any case, we have discussed this matter before, and there are some things that you can do in Matlab that are similar to the :? operator, but you start getting into function handles, and start needing nested functions if you want to duplicate the effect of expr2 or expr3 having side-effects. And there are some semantics you just can't duplicate at all because of the copy-on-write semantics of matlab...
|
Pages: 1 Prev: Is it a bug in memmapfile? or it's normal... Next: object extraction |