How to add values across an array within a constrained section
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I am working with on energy displacement in an array based on 12 months and 24 hour clock, I am trying to add several new values within a time constraint. Hopefully the below example illustrates better.
%
addvalue = rand(12,1); % The value that needs to be added to each hour of the time constraint across the array C
time = [1:8 23:24]; % The time constraint (or columns) the the addvalue needs to be added to
C = rand(12,24); % The array that represents a typical day for each month of the year over 24 hours
% Below is the loop I am using
for i = 1:size(C,1)
for h = 1:size(C,2)
for j = time
if C(i,h) == C(j)
C(i,h) = C(i,h) + addvalue(i);
end
end
end
end
With this loop I get the addvalue for the first couple of columns but not across the rest of the constraint I have set. If anyone have any advice on how to accomplish this it would be greatly appreciated.
0 commentaires
Réponse acceptée
Walter Roberson
le 8 Avr 2016
In your statement
if C(i,h) == C(j)
notice that you used C with two indices on the left but with one index on the right
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Analysis 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!