Matlab - Tamaño de matriz

   
Vista:

Tamaño de matriz

Publicado por Oscar Rodriguez jrodriguez@gmail.com (6 intervenciones) el 08/02/2013 23:26:36
Gracias Jose. Teniendo en cuenta tu corrección hice algunos ajustes al programa. En el archivo "parametrosVM" , creé una matriz vacía "x=[ ]", de esta manera tendré tres argumentos de salida, que serán los tres argumentos de entrada para la function "VMdisminuyealto2". Como sigue:

[x,BB6,CC6]=parametrosVM(VM);
VMdisminuyealto2(x,BB6,CC6);

Al ejecutar el programa me genera el sigueinte error:

??? Attempted to access BB6(1,2); index out of bounds because size(BB6)=[9,1].

Error in ==> VMdisminuyealto2 at 8
elseif x(i)<BB6(1,2);

Quiero saber si los ajustes que le hice son correctos y el porque me genera este error. Gracias por su ayuda y tiempo.


Código principal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r=5;
g=10;
R=g/10;

if (r<g)
disp Piezaincompleta

VM=input ('ingrese el valor de Volumen de material inyectado');
[x,BB6,CC6]=parametrosVM(VM);
VMdisminuyealto2(x,BB6,CC6);

switch logical(true)
case (g-R< r & r<g)

vf=[0 0 0 0 1 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-2*R< r & r<g-R)

vf=[0 0 0 0 2 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-3*R< r & r<g-2*R)

vf=[0 0 0 0 3 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-4*R< r & r<g-3*R)

vf=[0 0 0 0 4 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-5*R< r & r<g-4*R)

vf=[0 0 0 0 5 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-6*R< r & r<g-5*R)

vf=[0 0 0 0 6 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-7*R< r & r<g-6*R)

vf=[0 0 0 0 7 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-8*R< r & r<g-7*R)

vf=[0 0 0 0 8 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-9*R< r & r<g-8*R)

vf=[0 0 0 0 9 0];
Volumen_de_material_inyectado(BB6,vf);

case (g-9*R> r)

vf=[0 0 0 0 10 0];
Volumen_de_material_inyectado(BB6,vf);
end
disp vuelvainyectar;
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Primer archivo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x,AA6,DD6]=parametrosVM(ASG)

%pi es el valor del parametro que el usuario ingresa
%apartir del valor ASG y por regla de tres se hallan los 15 parametros
%de cada funcion de membresia pertenecientes a la salida del FIS.

%Parametros para VMdisminuyebajo2
GX1=ASG; GX2=(GX1*23.75)/25; GX3=(GX2*22.5)/23.75;
GX4=(GX3*21.25)/22.5; GX5=(GX4*20)/21.25; GX6=(GX5*18.75)/20;
GX7=(GX6*17.5)/18.75; GX8=(GX7*16.25)/17.5; GX9=(GX8*15)/16.25;
GXa=[GX9 GX8 GX7 GX6 GX5 GX4 GX3 GX2 GX1];

dif=(GX1-GX9)/2;

%Parametros para VMdisminuyemedio2
GX21=GX1-dif; GX22=GX2-dif; GX23=GX3-dif;
GX24=GX4-dif; GX25=GX5-dif; GX26=GX6-dif;
GX27=GX7-dif; GX28=GX8-dif; GX29=GX9-dif;
GXb=[GX29 GX28 GX27 GX26 GX25 GX24 GX23 GX22 GX21];


%Parametros para VMdisminuyealto2
GX31=GX21-dif; GX32=GX22-dif; GX33=GX23-dif;
GX34=GX24-dif; GX35=GX25-dif; GX36=GX26-dif;
GX37=GX27-dif; GX38=GX28-dif; GX39=GX29-dif;
GXc=[GX39 GX38 GX37 GX36 GX35 GX34 GX33 GX32 GX31];

ASH=ASG-GX39;
%Parametros para VMaumentaalto2
GE1=GX1+ASH; GE2=GX2+ASH; GE3=GX3+ASH;
GE4=GX4+ASH; GE5=GX5+ASH; GE6=GX6+ASH;
GE7=GX7+ASH; GE8=GX8+ASH; GE9=GX9+ASH;
GEa=[GE9 GE8 GE7 GE6 GE5 GE4 GE3 GE2 GE1];


%Parametros para VMaumentamedio2
GE21=GX21+ASH; GE22=GX22+ASH; GE23=GX23+ASH;
GE24=GX24+ASH; GE25=GX25+ASH; GE26=GX26+ASH;
GE27=GX27+ASH; GE28=GX28+ASH; GE29=GX29+ASH;
GEb=[GE29 GE28 GE27 GE26 GE25 GE24 GE23 GE22 GE21];


%Parametros para VMaumentabajo2
GE31=GX31+ASH; GE32=GX32+ASH; GE33=GX33+ASH;
GE34=GX34+ASH; GE35=GX35+ASH; GE36=GX36+ASH;
GE37=GX37+ASH; GE38=GX38+ASH; GE39=GX39+ASH;
GEc=[GE39 GE38 GE37 GE36 GE35 GE34 GE33 GE32 GE31];


% Apartir de este punto por minimos cuadrados se halla la ecuacion de la
% grafica para VMdisminuyebajo2 usando xa,y.
Y=[1 0.875 0.75 0.625 0.5 0.375 0.25 0.125 0];
m=2;
a=0;
n=9;
for i=1:n
a=a+GXa(1,i)*Y(1,i);
end

aa=0;
for i=1:n
aa=aa+GXa(1,i)*GXa(1,i)*Y(1,i);
end

b=0;
for i=1:n
b=b+GXa(1,i)*GXa(1,i);
end

bb=0;
for i=1:n
bb=bb+GXa(1,i)*GXa(1,i)*GXa(1,i);
end

bbb=0;
for i=1:n
bbb=bbb+GXa(1,i)*GXa(1,i)*GXa(1,i)*GXa(1,i);
end

c=0;
for i=1:n
c=c+GXa(1,i);
end

e=0;
for i=1:n
e=e+Y(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
aaa=[n c b e;c b bb a;b bb bbb aa];
cc=4;
ff=3;

for k=1:cc-1
aaa(k,:)=aaa(k,:)/aaa(k,k);
for j=k+1:ff
aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j+1;
end
k=k+1;
end

for k=ff:-1:2

for j=k-1:-1:1

aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j-1;
end
k=k-1;
end


% fprintf('\n\nEcuacion para VMdisminuyebajo2 \n\n');
% fprintf(' GY1 = %d*X^2+ %d*X + %d',aaa(3,4),aaa(2,4),aaa(1,4));

for i=1:n
GY1(1,i)=aaa(3,4)*GXa(1,i)*GXa(1,i)+aaa(2,4)*GXa(1,i)+aaa(1,4);
end

%global n11 n12 n13
Gn11= aaa(3,4);
Gn12= aaa(2,4);
Gn13= aaa(1,4);

%Aqui se encuentra la ecuacion para la grafica VMdisminuyemedio2 con xb,y.
Y=[1 0.875 0.75 0.625 0.5 0.375 0.25 0.125 0];
m=2;
a=0;
n=9;

for i=1:n
a=a+GXb(1,i)*Y(1,i);
end

aa=0;
for i=1:n
aa=aa+GXb(1,i)*GXb(1,i)*Y(1,i);
end

b=0;
for i=1:n
b=b+GXb(1,i)*GXb(1,i);
end

bb=0;
for i=1:n
bb=bb+GXb(1,i)*GXb(1,i)*GXb(1,i);
end

bbb=0;
for i=1:n
bbb=bbb+GXb(1,i)*GXb(1,i)*GXb(1,i)*GXb(1,i);
end

c=0;
for i=1:n
c=c+GXb(1,i);
end

e=0;
for i=1:n
e=e+Y(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
aaa=[n c b e;c b bb a;b bb bbb aa];
cc=4;
ff=3;

for k=1:cc-1
aaa(k,:)=aaa(k,:)/aaa(k,k);
for j=k+1:ff
aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j+1;
end
k=k+1;
end

for k=ff:-1:2

for j=k-1:-1:1

aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j-1;
end
k=k-1;
end


% fprintf('\n\nEcuacion para VMdisminuyemedio2 \n\n');
% fprintf (' GY2 = %d*X^2+ %d*X + %d',aaa(3,4),aaa(2,4),aaa(1,4));

for i=1:n
GY2(1,i)=aaa(3,4)*GXb(1,i)*GXb(1,i)+aaa(2,4)*GXb(1,i)+aaa(1,4);
end

%global n21 n22 n23
Gn21= aaa(3,4);
Gn22= aaa(2,4);
Gn23= aaa(1,4);

%Aqui se encuentra la ecuacion para la grafica VMdisminuyealto2 con xc,y.
Y=[1 0.875 0.75 0.625 0.5 0.375 0.25 0.125 0];
m=2;
a=0;
n=9;

for i=1:n
a=a+GXc(1,i)*Y(1,i);
end

aa=0;
for i=1:n
aa=aa+GXc(1,i)*GXc(1,i)*Y(1,i);
end

b=0;
for i=1:n
b=b+GXc(1,i)*GXc(1,i);
end

bb=0;
for i=1:n
bb=bb+GXc(1,i)*GXc(1,i)*GXc(1,i);
end

bbb=0;
for i=1:n
bbb=bbb+GXc(1,i)*GXc(1,i)*GXc(1,i)*GXc(1,i);
end

c=0;
for i=1:n
c=c+GXc(1,i);
end

e=0;
for i=1:n
e=e+Y(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
aaa=[n c b e;c b bb a;b bb bbb aa];
cc=4;
ff=3;

for k=1:cc-1
aaa(k,:)=aaa(k,:)/aaa(k,k);
for j=k+1:ff
aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j+1;
end
k=k+1;
end

for k=ff:-1:2

for j=k-1:-1:1

aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j-1;
end
k=k-1;
end


% fprintf('\n\nEcuacion para VMdisminuyealto2 \n\n');
% fprintf(' GY3 = %d*X^2 + %d*X + %d',aaa(3,4),aaa(2,4),aaa(1,4));

for i=1:n
GY3(1,i)=aaa(3,4)*GXc(1,i)*GXc(1,i)+aaa(2,4)*GXc(1,i)+aaa(1,4);
end

%global n31 n32 n33
Gn31= aaa(3,4);
Gn32= aaa(2,4);
Gn33= aaa(1,4);


%Aqui se encuentra la ecuacion para la grafica VMaumentaalto2 con ea,ye.
Ye=[0 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1];
m=2;
a=0;
n=9;

for i=1:n
a=a+GEa(1,i)*Ye(1,i);
end

aa=0;
for i=1:n
aa=aa+GEa(1,i)*GEa(1,i)*Ye(1,i);
end

b=0;
for i=1:n
b=b+GEa(1,i)*GEa(1,i);
end

bb=0;
for i=1:n
bb=bb+GEa(1,i)*GEa(1,i)*GEa(1,i);
end

bbb=0;
for i=1:n
bbb=bbb+GEa(1,i)*GEa(1,i)*GEa(1,i)*GEa(1,i);
end

c=0;
for i=1:n
c=c+GEa(1,i);
end

e=0;
for i=1:n
e=e+Ye(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
aaa=[n c b e;c b bb a;b bb bbb aa];
cc=4;
ff=3;

for k=1:cc-1
aaa(k,:)=aaa(k,:)/aaa(k,k);
for j=k+1:ff
aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j+1;
end
k=k+1;
end

for k=ff:-1:2

for j=k-1:-1:1

aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j-1;
end
k=k-1;
end


% fprintf('\n\nEcuacion para VMaumentaalto2 \n\n');
% fprintf(' GY4 = %d*X^2+ %d*X + %d',aaa(3,4),aaa(2,4),aaa(1,4));

for i=1:n
GY4(1,i)=aaa(3,4)*GEa(1,i)*GEa(1,i)+aaa(2,4)*GEa(1,i)+aaa(1,4);
end

%global m11 m12 m13
Gm11= aaa(3,4);
Gm12= aaa(2,4);
Gm13= aaa(1,4);


%Aqui se encuentra la ecuacion para la grafica VMaumentamedio2 con eb,ye.
Ye=[0 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1];
m=2;
a=0;
n=9;

for i=1:n
a=a+GEb(1,i)*Ye(1,i);
end

aa=0;
for i=1:n
aa=aa+GEb(1,i)*GEb(1,i)*Ye(1,i);
end

b=0;
for i=1:n
b=b+GEb(1,i)*GEb(1,i);
end

bb=0;
for i=1:n
bb=bb+GEb(1,i)*GEb(1,i)*GEb(1,i);
end

bbb=0;
for i=1:n
bbb=bbb+GEb(1,i)*GEb(1,i)*GEb(1,i)*GEb(1,i);
end

c=0;
for i=1:n
c=c+GEb(1,i);
end

e=0;
for i=1:n
e=e+Ye(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
aaa=[n c b e;c b bb a;b bb bbb aa];
cc=4;
ff=3;

for k=1:cc-1
aaa(k,:)=aaa(k,:)/aaa(k,k);
for j=k+1:ff
aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j+1;
end
k=k+1;
end

for k=ff:-1:2

for j=k-1:-1:1

aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j-1;
end
k=k-1;
end


% fprintf('\n\nEcuacion para VMaumentamedio2 \n\n');
% fprintf(' GY5 = %d*X^2 +%d*X + %d',aaa(3,4),aaa(2,4),aaa(1,4));

for i=1:n
GY5(1,i)=aaa(3,4)*GEb(1,i)*GEb(1,i)+aaa(2,4)*GEb(1,i)+aaa(1,4);
end

%global m21 m22 m23
Gm21= aaa(3,4);
Gm22= aaa(2,4);
Gm23= aaa(1,4);


%Aqui se encuentra la ecuacion para la grafica VMaumentabajo2 con ec,ye.
Ye=[0 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1];
m=2;
a=0;
n=9;

for i=1:n
a=a+GEc(1,i)*Ye(1,i);
end

aa=0;
for i=1:n
aa=aa+GEc(1,i)*GEc(1,i)*Ye(1,i);
end

b=0;
for i=1:n
b=b+GEc(1,i)*GEc(1,i);
end

bb=0;
for i=1:n
bb=bb+GEc(1,i)*GEc(1,i)*GEc(1,i);
end

bbb=0;
for i=1:n
bbb=bbb+GEc(1,i)*GEc(1,i)*GEc(1,i)*GEc(1,i);
end

c=0;
for i=1:n
c=c+GEc(1,i);
end

e=0;
for i=1:n
e=e+Ye(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
aaa=[n c b e;c b bb a;b bb bbb aa];
cc=4;
ff=3;

for k=1:cc-1
aaa(k,:)=aaa(k,:)/aaa(k,k);
for j=k+1:ff
aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j+1;
end
k=k+1;
end

for k=ff:-1:2

for j=k-1:-1:1

aaa(j,:)=aaa(j,:)-aaa(k,:)*aaa(j,k);
j=j-1;
end
k=k-1;
end


% fprintf('\n\nEcuacion para VMaumentabajo2 \n\n');
% fprintf(' GY6 = %d*X^2 +%d*X + %d',aaa(3,4),aaa(2,4),aaa(1,4));

for i=1:n
GY6(1,i)=aaa(3,4)*GEc(1,i)*GEc(1,i)+aaa(2,4)*GEc(1,i)+aaa(1,4);
end

%global m31 m32 m33
Gm31= aaa(3,4);
Gm32= aaa(2,4);
Gm33= aaa(1,4);

%Graficas
hold on
plot(GXa,GY1)
plot(GXb,GY2)
plot(GXc,GY3)
plot(GEa,GY4)
plot(GEb,GY5)
plot(GEc,GY6)
grid
xlabel('x');ylabel('y')
x=[];
AA6=[GX39 GX38 GX37 GX36 GX35 GX34 GX33 GX32 GX31;GX29 GX28 GX27 GX26 GX25 GX24 GX23 GX22 GX21;GX9 GX8 GX7 GX6 GX5 GX4 GX3 GX2 GX1;GE39 GE38 GE37 GE36 GE35 GE34 GE33 GE32 GE31;GE29 GE28 GE27 GE26 GE25 GE24 GE23 GE22 GE21;GE9 GE8 GE7 GE6 GE5 GE4 GE3 GE2 GE1];
DD6 = [Gn31 Gn32 Gn33;Gn21 Gn22 Gn23;Gn11 Gn12 Gn13;Gm31 Gm32 Gm33;Gm21 Gm22 Gm23;Gm11 Gm12 Gm13];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Segundo archivo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y =VMdisminuyealto2(x,BB6,CC6)%(x,params)%

for i=1:length (x)
if x(i)<0.01
y(i)=0;
elseif x(i)<BB6(1,1);%params (1)%
y(i)=1;
elseif x(i)<BB6(1,2);%params (2)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,3);%params (3)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,4);%params (4)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,5);%params (5)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,6);%params (6)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,7);%params (7)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,8);%params (8)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)<BB6(1,9);%params (9)%
x1 = x(i);
y(i)= (CC6(1,1)*x1^2+CC6(1,2)*x1+CC6(1,3));%(2.8797324*10^-4*x1^2-0.0325186*x1+0.9149492);%
elseif x(i)>BB6(1,9);%params (15)%
y(i)=0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder