Filter löschen
Filter löschen

How can i change my index number (for a==1) and get unique i value? i=1:200 j=1:24

2 Ansichten (letzte 30 Tage)
.........
C=intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);
a=reshape(C,24,200);
a
[col,i]=find(a==1)
m=[i,col]
Result is
m =
1 10
2 1
2 2
2 3
2 4
3 1
3 2
3 3
5 1
5 2
5 4
6 2
7 1
7 2
7 3
7 4
8 2
9 1
10 2
11 1
11 2
11 3
12 1
12 2
12 3
13 2
14 9
14 10
15 1
15 2
15 4
16 1
16 2
16 3
16 4
17 1
17 2
17 3
18 1
19 1
19 2
19 3
20 1
20 2
20 3
20 4
21 2
22 2
23 1
25 1
25 2
27 1
27 4
29 9
30 1
30 2
30 4
31 2
32 3
33 2
34 2
35 2
36 2
37 2
38 2
39 11
42 1
42 2
42 4
43 2
44 2
45 2
46 1
46 2
46 3
47 1
47 2
47 4
48 1
48 2
49 1
50 1
50 2
51 1
52 3
53 1
54 4
55 1
55 2
55 3
55 4
56 1
56 2
57 1
57 2
57 3
58 1
58 2
60 2
61 1
61 2
62 2
62 4
63 1
63 2
64 10
65 1
65 2
66 2
67 2
68 1
68 2
69 9
69 10
69 12
70 9
70 10
70 12
73 1
73 2
74 1
74 2
74 3
74 4
75 2
76 2
78 2
79 2
80 2
82 3
83 1
83 2
83 3
84 2
85 1
86 2
89 3
90 2
91 2
92 2
93 2
94 1
94 2
94 4
95 1
95 2
96 1
96 2
97 1
97 2
97 3
98 1
98 2
98 3
99 1
100 1
100 4
101 1
101 4
102 9
102 10
103 1
103 2
103 3
104 1
104 2
104 4
105 1
105 2
106 1
107 1
108 1
109 2
110 2
111 2
112 2
113 1
113 2
114 2
115 1
116 1
116 2
117 1
117 2
117 3
118 1
119 2
120 2
121 1
121 2
121 3
122 1
122 2
122 3
123 1
123 2
123 3
125 2
129 2
130 1
130 2
130 3
131 1
131 2
131 3
131 4
132 2
133 1
133 2
133 3
134 1
134 3
135 1
135 2
135 3
135 4
136 1
136 2
136 3
137 2
139 1
139 2
140 1
140 2
140 3
140 4
142 1
142 2
144 3
145 1
145 2
145 3
145 4
146 9
146 10
147 9
147 10
149 11
150 2
151 2
152 1
152 2
152 4
153 4
154 2
155 2
156 2
157 2
158 1
158 2
158 3
159 4
160 1
160 2
160 3
160 4
161 4
162 3
163 1
164 1
164 3
165 4
166 4
167 1
167 2
167 4
168 3
169 1
169 3
170 1
170 4
171 1
171 3
172 1
173 1
173 2
174 2
175 9
176 12
177 9
177 11
178 9
178 11
179 9
180 9
181 9
182 1
182 2
182 4
183 1
183 2
183 3
183 4
184 1
185 1
185 2
185 3
185 4
186 4
187 1
187 2
187 4
188 1
189 4
190 1
190 2
190 3
190 4
191 1
192 2
193 1
193 3
194 1
194 2
195 1
195 2
195 3
196 1
197 1
198 1
198 2
198 3
199 1
199 2
200 1
But I want to unique i and change index value. I wrote this but it wrote 3 for every i
for i=1:200
for j=1:4 | j==13:16
j=1;
end
for j=5:8 | j==17:20
j=2;
end
for j=9:12 | j==21:24
j=3;
end
d=[i,j]
end
For example i have two i=14 but i want to code writes just
14 3
15 1
  2 Kommentare
Geoff Hayes
Geoff Hayes am 30 Apr. 2016
Selin - you may want to provide a simpler example of what you are attempting to do. It is unclear from the above what you really want. I see that in your results you have
14 9
14 10
but you seem to want
14 3
15 1
instead. Is that the case?
Also, what are you trying to do with
for j=1:4 | j==13:16
What does that mean to you? Do you just want to iterate over 1,2,3,4,13,14,15,16 and skip the 5 through 12?
Selin Ozdemir
Selin Ozdemir am 30 Apr. 2016
Bearbeitet: Selin Ozdemir am 30 Apr. 2016
Yes i want to
14 3
5 1
Actually, every i value has 24 possibilities. These are gruoping four each. In the for loop I wanted to write when j= 1:4 and 13:16, code will write j=1 anymore. For j=5:8 and 17:20 code will write j=2 and j=9:12 21:24 code will write j=3 anymore.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 30 Apr. 2016
i = (1:24).';
j = ceil( (mod(i-1,12)+1) / 4 );
d = [i, j];

Community Treasure Hunt

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

Start Hunting!

Translated by