Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
How can I deal spesific value and add constraint?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have matrix T
T =[1 3
2 1
3 1
4 4
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 3
15 1
16 1
17 1
18 1
19 1
20 1];
I found first column values that have zero in second column with this code
idx = find( T( :, 2 ) == 1 )
idx =
2
3
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
After this point I want to add constraint. This constraint must find equivalent of idx's result(2,3,5,6,7,8,9,10....) in Y1 and I want summation of these Y1 values smaller than 20.
Y1=[0 12 0 0 3 1 3 1 1 1 9 0 1 0 0 10 12 1 2 3];
And then for remainder idx values, code must do same thing with Y2
Y2=[0 57 0 0 0 0 11 1 1 1 45 0 1 0 4 48 59 1 7 13];
0 Commenti
Risposte (1)
Andrei Bobrov
il 12 Mag 2016
Т = [1 3
2 1
3 1
4 4
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 3
15 1
16 1
17 1
18 1
19 1
20 1];
Y1=[0 12 0 0 3 1 3 1 1...
1 9 0 1 0 0 10 12 1 2 3]';
Y2=[0 57 0 0 0 0 11 1 1...
1 45 0 1 0 4 48 59 1 7 13]';
t = T(:,2) == 1;
out1 = sum(Y1(t & Y1 < 20))
out2 = sum(Y2(t & Y2 < 20))
0 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!