"CAE Emmerton" wrote in message <ier78q$1dj$1@fred.mathworks.com>...
> I'm new to Matlab with little programming experience. Here's what I'm trying to do:
> I want to cycle y(1,1) through all x's (x(1,1) to x(4,1)) and then cycle y(2,1) through all x's (x(1,1) to x(4,1)). I'm trying multiple loops but I can't seem to get this to work. I'm trying to apply this through a much larger dataset, so I'm starting small:
>
> x=[2 5 6 1]'
> y=[4 5]'
>
> here are the conditions I just made up:
> if x()>y();
> z()=x();
> else z()=NaN;
> end;
>
> The answer hopefully would be:
> z=
> NaN
> 5
> 6
> NaN
> NaN
> NaN
> NaN
> 6
> NaN
doc bsxfun
%%%
%Data
x=[2 5 6 1]';
y=[4 5];
%Engine
idx = bsxfun(@(x,y)(x>y),x,y);
xfull = repmat(x,[1,size(y,2)]);
z(idx) = xfull(idx);
z(~idx) = nan;
z = z.'
%SCd
%%%
