필터 지우기
필터 지우기

How to add values across an array within a constrained section

조회 수: 2 (최근 30일)
Thomas
Thomas 2016년 4월 8일
댓글: Thomas 2016년 4월 9일
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.

채택된 답변

Walter Roberson
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by