Need Help in Simplifying code

1 vue (au cours des 30 derniers jours)
Jefri Nazulrullah bin Zulkepli Amin
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 commentaire
dpb
dpb le 13 Juil 2019
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.

Connectez-vous pour commenter.

Réponses (1)

Samatha Aleti
Samatha Aleti le 16 Juil 2019
You can use the find function for vectorization. Here is how you can simplify the code.
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;

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by