Effacer les filtres
Effacer les filtres

I have tried running this code and I keep getting this following error. Attempted to access P(1,2); index out of bounds because numel(P)=1. Error in Assignment_7 (line 24) A = [P(1,1) P(1,2) P(1,3) P(1,4) P(1,5) P(1,6) P(1,7) P(1,8) FTR1 FTR2 FTR3

1 vue (au cours des 30 derniers jours)
clear
clc
Bij = [0 33.33 0 33.33 153.8 0 0 0;
0 0 100 0 0 0 0 0;
0 0 0 33.33 0 0 0 0;
0 0 0 0 33.33 0 0 0;
0 0 0 0 0 50 0 0;
40 0 0 0 0 0 0 0;
0 0 0 80 0 0 0 45.45;
0 0 55.55 0 0 0 0 0];
P = [];
delta = [0 0 0 0 0 0 0 0];
x0=[50 50 50 50 50 50 0 0 0 0 0 0 0 0];
for i = 1:1:8
for j = 1:1:8
P = Bij(i,j);
end
end
A = [P(1,1) P(1,2) P(1,3) P(1,4) P(1,5) P(1,6) P(1,7) P(1,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(2,1) P(2,2) P(2,3) P(2,4) P(2,5) P(2,6) P(2,7) P(2,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(3,1) P(3,2) P(3,3) P(3,4) P(3,5) P(3,6) P(3,7) P(3,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(4,1) P(4,2) P(4,3) P(4,4) P(4,5) P(4,6) P(4,7) P(4,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(5,1) P(5,2) P(5,3) P(5,4) P(5,5) P(5,6) P(5,7) P(5,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(6,1) P(6,2) P(6,3) P(6,4) P(6,5) P(6,6) P(6,7) P(6,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(7,1) P(7,2) P(7,3) P(7,4) P(7,5) P(7,6) P(7,7) P(7,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(8,1) P(8,2) P(8,3) P(8,4) P(8,5) P(8,6) P(8,7) P(8,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6];
B=[0 150 0 140 380 0 0 0 300 300 300 300 300 300;
0 0 120 0 0 0 0 0 300 300 300 300 300 300;
0 0 0 230 0 0 0 0 300 300 300 300 300 300;
0 0 0 0 150 0 0 0 300 300 300 300 300 300;
0 0 0 0 0 300 0 0 300 300 300 300 300 300;
250 0 0 0 0 0 0 0 300 300 300 300 300 300;
0 0 0 350 0 0 340 300 300 300 300 300 300;
0 0 240 0 0 0 0 0 300 300 300 300 300 300];
Aeq=[ 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0;
0 0 1 0.4 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 -1 0.6 0 0 0 0 0 0 0 0;
0.5 1 0 0 0 -1 0 0 0 0 0 0 0 0;
-1 -1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0 0 0 0 0;
0.5 0 0 0 0 1 0 0 0 0 0 0 0 0];
Beq=Bij*delta - [0;0;0;100;-100;-80;80;0];
ub = [ 300 300 300 300 300 300 30 30 30 30 30 30 30 30];
lb = [ -300 -300 -300 -300 -300 -300 -30 -30 -30 -30 -30 -30 -30 -30];
[Solution C] = fmincon(@obj,x0,A,B,Aeq,Beq,lb,ub);
FTR = Solution(1:6)
Delta = SOlution(7:14)
C

Réponses (2)

Star Strider
Star Strider le 1 Nov 2015
You did not create an array for ‘P’. It is a scalar, not an array, and is equal to Bij(8,8), the last value assigned to it in the loop.

Image Analyst
Image Analyst le 2 Nov 2015
Maybe instead of the for loop, you simply want to set P equal to Bij - I don't know your intent. But your loops are the same as this:
P = Bij;
If you do that, then P will be an array and have a 1,2 element. As you have it, P is just a single scalar number that gets overwritten every time though your loop.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by