Borrar filtros
Borrar filtros

How to add values across an array within a constrained section

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by