Need Help in Simplifying code
14 次查看(过去 30 天)
显示 更早的评论
I need tips in simplifying code for the function to run faster as i am not too familiarised with the vectorisation.
Here is the code:
for j = 1:length(SurfAz)
AOI(:,j) = pvl_getaoi(SurfTilt, SurfAz(j), SunZen, SunAz);
end
TrackerAz = zeros(length(SunAz),1);
for j=1:length(SunE1)
if SunE1(j)>=0
Min = min(AOI(j,:));
idxm = AOI(j,:)==Min;
TrackerAz(j) = SurfAz(idxm);
else
TrackerAz(j) = 60;
end
end
1 个评论
dpb
2019-7-13
Don't know other arguments to pvl_getaoi nor whether it is vectorized to take array inputs or not.
What does it return? As written it looks like it returns more than one value?
Did you preallocate AOI?
Need dimensions of the arrays -- there seems quite a bit of inconsistency in between what appear to be vectors versus arrays.
Also, NB: length() returns max(size(X)) for input array X. It is NOT to be relied upon to tell you the number of rows/columns in an array; use size() for the proper dimension instead to avoid surprises/errors.
回答(1 个)
Samatha Aleti
2019-7-16
for j = 1:length(SurfAz)
AOI(:,j) = pvl_getaoi(SurfTilt, SurfAz(j), SunZen, SunAz);
end
TrackerAz = zeros(length(SunAz),1);
idx1 = find(SunE1>=0)
idx2 = find(SunE1<0)
for i =1:length(idx1)
[m,mIdx] = min(AOI(idx1(i),:));
TrackerAz(idx1(i)) = x(mIdx);
end
TrackerAz(idx2) = 60;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!