Effacer les filtres
Effacer les filtres

Assign values based on multiple index thresholds - vectorised solution?

1 vue (au cours des 30 derniers jours)
Catriona Fyffe
Catriona Fyffe le 20 Mar 2020
Commenté : Catriona Fyffe le 20 Mar 2020
I would like to assign different values to a variable (SRF) which is used in a loop which is running over time (at hourly interval). Currently there is a matrix of SRF values in a matrix (41,3). I want to extract the list of values (all 41) depending upon the year (1:3). In a later loop I pull out each value from the list, but first I need to set the list using the year. I have already extracted the min and max indices (relating to the time) of each year in a variable:
year_no_idx =
1 3816
3817 11832
11833 16392
I want to do this within the time loop which is already running over each hour, but I don't want to add another loop to run over the year too, as there are several other dimensions (3 more) coming later and I would rather not complicate things further. I feel like there must be a simple way to do this in a vectorised way, but I really can't find any clues to help. I can't just write three if statements as later I want to run the same code for other data, and later also for every month, so it has to be robust. Thanks for any suggestions!
  1 commentaire
Catriona Fyffe
Catriona Fyffe le 20 Mar 2020
Its ok I decided to implement a seperate loop before the main loop, which does what I was after. It would still be nice to know if you can vectorise this sort of thing.
for y=1:max(year_no)
for i=x1:x2
if (year_no_idx(y,1)<=i) && (year_no_idx(y,2)>=i)
SRF_hourly_year(i,:)=SRF_list_fine_year(:,y);
end
end
end

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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