Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How can I deal spesific value and add constraint?

1 vue (au cours des 30 derniers jours)
Selin Ozdemir
Selin Ozdemir le 12 Mai 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
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];

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 12 Mai 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))

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by