Error when manipulating values on a matrix
显示 更早的评论
Hello there,
I've got a few problems with my code. I'm going to explain: I have a matrix that is randomly generated: Populacao1 = [((randi([-1 1], n_individuos, n_centrais*int_tempo)))];
n_individuos=10 (or another number) n_centrais=2 (or more) and int_tempo = 10 (or more)
Populacao1 has only 1, -1 and 0 values. Now the problem begins.
I want to be able to keep 4 matrix (caulda_turbinado_c1, caudal_bombado_c1 and caulda_turbinado_c2, caudal_bombado_c2)
caudal_turbinado_c1 is the first (n_centrais*int_tempo)/2 where the the value equals 1 and caudal_bombado_c2 is when it equals -1. caudal_turbinado_c2 and bombado_c2 are the same in the other half of the matrix. the problem is that it doesn't work. Don't know why :s
for i=1:n_individuos
for j=1:int_tempo*n_centrais
if j <= int_tempo
if(Populacao1(i,j)==1)
caudal_turbinado_c1(i,j) = 100;
if(Populacao1(i,j)==-1)
caudal_bombado_c1(i,j)=200;
end
end
end
if j > int_tempo && j<=int_tempo*n_centrais
if(Populacao1(i,j)==1)
caudal_turbinado_c2(i,j-int_tempo) = 400;
if(Populacao1(i,j)==-1)
caudal_bombado_c2(i,j-int_tempo)=200;
end
end
end
end
end
Thanks in advance
4 个评论
Azzi Abdelmalek
2013-1-2
If you provide data to test your code, it will be helpful
Jan
2013-1-2
Pleas explain "it doesn't work" with any details. Do you get an error message or do the results differ from your expectations?
André Pacheco
2013-1-3
André Pacheco
2013-1-3
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!