MATLAB: Store sets of values as indices in a matrix

matrixstore values

Hi,
I have a function which produces a set of horizontal and vertical graph axes intercepts. There are 120 sets of these intercepts:
for Z = 1:120
hrz = hix(x(:,Z),mb(:,Z))'; %[X Y] Matrix of horizontal intercepts
vrt = vix(y(:,Z),mb(:,Z))'; %[X Y] Matrix of vertical intercepts
end
I want to store each of these sets of intercepts in a matrix, i.e. I want to be able to call the second set of intercepts by simply calling matrix(2).
Is anyone aware of a way to achieve this?
Thanks

Best Answer

I'm assuming that hix and vix are functions, and I'm assuming that for each pair of vector input, they each return a vector of the same size as the input. In which case,
hrz = zeros(size(x)); %predeclare output matrix
vrt = zeros(size(x));
for Z = 1:120
hrz(:, Z) = hix(x(:, Z), mb(:, Z));
vrt(:, Z) = vix(y(:, Z), mb(:, Z));
end