MATLAB: Saving data from equation in Marix or Grid then call them later

saving data from equation in matrix

In Mathlab if we have
U=f(Y)+f(Z)
Y have 20 different values
Z have 100 different values
I mean if Y=1 then Z will have 100 different values. For each Y there will be 100 values for Z. this mean I will have 100*20 matrix.
My question is in Mathlab how I can save the output from any equation in any matrix or grid? for this case (100*20)
For example U=Y*Z (when Y=1 then Z have 100 values. Then when Y=3.2 then Z will have 100 new different values)
I mean I need to save the result from any equation in matrix or grid using Mathlab. I need to call these numbers later to use in another function. In addition how I can call each number in this matrix to use it in another equation and how I can drew this numbers ( I mean the number in matrix or grid)

Best Answer

Use the bsxfun function:
f = @(x) sin(x + cos(x));
Y = 0:19;
Z = 1:100;
U = bsxfun(@plus, f(Y), f(Z).'); % Transpose (.') So One Is A Column Vector
Pass ā€˜Uā€™ to your other function as an argument to it.