From: Jan Simon on
Dear Matt!

> > for iC = 1:numel(C)
> > aC = C{iC};
> > aC(aC >= 0.5) = NaN;
> > C{iC} = aC;
> > end

> for ii = 1:numel(C)
> C{ii}(C{ii}(:)>.5) = nan;
> end

Which one is faster on your machine?
I assume the aC method creates a deep copy, while C{ii){C{ii}(:))>.5) is not just a damn tricky smiley but used just shared data copies?

Jan
From: Oleg Komarov on
"Steven Lord" <slord(a)mathworks.com> wrote in message <hlk2b9$fpf$1(a)fred.mathworks.com>...
>
> "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message
> news:hljq9l$48t$1(a)fred.mathworks.com...
> >> So for the "much-requested built-in IFF function", would you want it to
> >> demonstrate this behavior or to operate element-by-element, and more
> >> importantly how many people do you believe would expect it to work the
> >> other way? [I'm genuinely interested in your answers to the two parts of
> >> this question.]
> >>
> >> --
> >> Steve Lord
> >> slord(a)mathworks.com
> >> comp.soft-sys.matlab (CSSM) FAQ:
> >> http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
> > Not sure i understod your question but considering
> > cellfun(@(x) iff(x>.5,NaN,x), data);
> > I would expect for ii = numel(data)
> > IDX = data{1} > .5 data{1}(IDX) = NaN
> > data{1}(~IDX) = x % (which is equal to itself in this specific case)
> > end
> >
> > I wouldn't want if all(data{1} > .5) data{1}(:) = NaN; % neither data{1} =
> > NaN;
> > else data{1}(:) = x;
> > end
>
> Let me simplify the question by removing the extraneous CELLFUN. What would
> your expectation be for the contents of y after these lines of code were
> executed?
>
> clear y
> x = 0:0.1:1;
> y = iff(x > 0.5, NaN, x)
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
I'd expect element by element:
0.1 0.2 0.3 0.4 0.5 NaN NaN NaN NaN NaN.

The other behavior can be described as follows:
iff(all(x > 0.5), NaN, x)

then if x = .6: .1 :1
x = NaN NaN NaN NaN NaN

Oleg
From: Yair Altman on
I second Oleg's expectations, but my point with IFF was really simpler - I did not intend IFF to replace CELLFUN, but just to be used by it. This way, it would only work on a single cell-value each time:

cellfun(@(x) iff(x>.5,NaN,x), data)

Of course, data's cell values may themselves be non-scalars, in which case my simple IFF implementation would need to be more complex, but as far as I understood the OP's question, this was not the case, and I just wanted to show a basic solution template.

Again - I fully agree that a built-in IFF would need to handle cells, arrays, structs, objects and other complex types. But even a very basic implementation would be an improvement, because inline conditional statements are currently unavailable in CELLFUN/ARRAYFUN and their kin.

Yair