In MATLAB I have
[Z,S]=meshgrid(0.01:0.01:1)
and I also have a 100000x2 matrix called X, each row has two sets of data - p is the first column and x is the 2nd.
I want to compute exp^(-S*X(j,2)).(*Z.^X(j,1)) where j indexes the row. The result should be a 100x100x100000 matrix. This will then be averaged along the 3rd dimension and a mesh plot will be produced. I've tried using a for loop
[Z,S]=meshgrid(0.01:0.01:1)
for j=1:100000
phi(j)=exp^(-S.*X(j,2)).*(Z.^X(j,1))
end
to produce the 100x100x100000 array I need. However this gives me the error
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in phi (line 4)
phi(j)=exp(-S.*X(j,2)).*(Z.^X(j,1));
I'm not sure why this is happening? Can anyone figure out a better way of trying to find the result I want? Because I'm guessing there could be a fully vectorised solution (or least use of for loops)?
phi. You are obviously getting a dimension mismatch because of that.