From: Ahmad Alkandri on
hi

what i mean by '' cover '' is to run the for loop and use all the vector values of the variables a, b and y

(ie. a = [1 2 3 4 5 6 7 8 9 ] ....b = [ 7 6 5 4 ] . .. . y = [1 2 5 6 7 ] )

so the for loop will cover every possible combination within these variables

Ahmad
From: Walter Roberson on
Ahmad Alkandri wrote:

> what i mean by '' cover '' is to run the for loop and use all the vector
> values of the variables a, b and y
>
> (ie. a = [1 2 3 4 5 6 7 8 9 ] ....b = [ 7 6 5 4 ] . .. . y = [1 2 5 6 7
> ] )
>
> so the for loop will cover every possible combination within these
> variables

[A, B, Y] = ndgrid(a, b, y);

k = A + B + Y;

disp(k(:));
From: Steven Lord on

"Walter Roberson" <roberson(a)hushmail.com> wrote in message
news:vckNn.32763$h57.614(a)newsfe22.iad...
> Ahmad Alkandri wrote:
>
>> what i mean by '' cover '' is to run the for loop and use all the vector
>> values of the variables a, b and y
>>
>> (ie. a = [1 2 3 4 5 6 7 8 9 ] ....b = [ 7 6 5 4 ] . .. . y = [1 2 5 6
>> 7 ] )
>>
>> so the for loop will cover every possible combination within these
>> variables
>
> [A, B, Y] = ndgrid(a, b, y);
>
> k = A + B + Y;
>
> disp(k(:));

Another approach is to give the three vectors different orientations and
then use BSXFUN twice.

a = 1:9;
b = 7:-1:4;
c = [1 2 5 6 7];
ab = bsxfun(@plus, a, b.');
abc = bsxfun(@plus, ab, reshape(c, 1, 1, []));

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com