The issue encountered at angle 164º occurs because the variable “lon501” receives an empty value at that specific angle, which leads to a runtime error when assigning results to the “DI_CORR” matrix.
To prevent this error while maintaining the current set of equations, it is recommended to ensure that all variables assigned to the matrix are scalars, substituting empty values with “NaN” or another placeholder as appropriate.
The following line of code can be replaced by:
DI_CORR(c+1,:) =[c, lon100, lat100, lon250, lat250, lon501, lat501, lon502, lat502, lon503, lat503, lon1001, lat1001, lon1002, lat1002, lon1003, lat1003, lon1000, lat1000];
by below lines of code:
results = {lon100, lat100, lon250, lat250, lon501, lat501, lon502, lat502, lon503, lat503, lon1001, lat1001, lon1002, lat1002, lon1003, lat1003, lon1000, lat1000};
for k = 1:length(results)
if isempty(results{k})
results{k} = NaN;
else
results{k} = results{k}(1);
end
end
DI_CORR(c+1,:) = [c, results{:}];
This approach ensures that the assignment to DI_CORR will not fail due to empty outputs.
For further information, please refer to the following MATLAB documentation links: