How to add values across an array within a constrained section
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2016-4-8
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!