I have function called buildRay which returns a 1×4 matrix. I call it multiple times like so:
rays = zeros(numRays, 4);
for j = 1:numRays
rays(j, :) = buildRay(particle, (j-1)*anglePart, rayLength);
end
If I try and replace the loop with:
rays(1:numRays, :) = buildRay(particle, ((1:numRays)-1).*anglePart, rayLength);
I get the following error
??? Subscripted assignment dimension mismatch.
and I don’t understand why.
Could someone please tell me what I’m doing wrong?
Thanks.
As the error message state, your left and right expressions have different size. You cannot do it in MATLAB.
To avoid for-loop you can use ARRAYFUN function: