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!