Attempted to access X1(1); index out of bounds because numel(X1)=0. Error in (line 108)

1 view (last 30 days)
Hi, here is my script code, I just copy it here.
clear all;
close all;
[x1,x2,x3,x4,x5,x6]=nbc(6);
func=(~x1*~x2*x3)+(x1*~x2*x4)+(~x1*x2*x5)+(x1*x2*x6);
btab(func,x1,x2,x3,x4,x5,x6);
Function = [ ];
X1 = [ ];
X2 = [ ];
X3 = [ ];
X4 = [ ];
X5 = [ ];
X6 = [ ];
for i=1:16
if (b2d(func(i))==0)
Function(i)=0;
else
Function(i)=1;
end
end
for i=1:16
if (b2d(x1(i))==0)
X1 (i)=0;
else
X1 (i)=1;
end
end
for i=1:16
if (b2d(x2(i))==0)
X2 (i)=0;
else
X2 (i)=1;
end
end
for i=1:16
if (b2d(x3(i))==0)
X3 (i)=0;
else
X3 (i)=1;
end
end
for i=1:16
if (b2d(x4(i))==0)
X4 (i)=0;
else
X4 (i)=1;
end
end
for i=1:16
if (b2d(x5(i))==0)
X5 (i)=0;
else
X5 (i)=1;
end
end
for i=1:16
if (b2d(x6(i))==0)
X6 (i)=0;
else
X6 (i)=1;
end
end
for i=1:15
for j = (i+1):16
if ((X1(i) ~= X1(j)) && (X2(i) == X2(j)) && (X3(i) == X3(j)) && (X4(i) == X4(j)) && (X5(i) == X5(j)) && (X6(i) == X6(j)) && (Function(i) ~=Function(j)))
Temp1 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i)];
Temp2 = [X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
Store1 = [Temp1; Temp2];
end
if ((X1(i) == X1(j)) && (X2(i) ~= X2(j)) && (X3(i) == X3(j)) && (X4(i) == X4(j)) && (X5(i) == X5(j)) && (X6(i) == X6(j)) && (Function(i) ~=Function(j)))
Temp1 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i)];
Temp2 = [X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
Store2 = [X1(i) X2(i) X3(i) X4(i) X5(i) Function(i);X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
end
if ((X1(i) == X1(j)) && (X2(i) == X2(j)) && (X3(i) ~= X3(j)) && (X4(i) == X4 (j)) && (X5(i) == X5(j)) && (X6(i) == X6(j)) && (Function(i) ~=Function(j)))
Temp1 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i)];
Temp2 = [X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
Store3 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i);X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
end
if ((X1(i) == X1(j)) && (X2(i) == X2(j)) && (X3(i) == X3(j)) && (X4(i) ~= X4 (j)) && (X5(i) == X5(j)) && (X6(i) == X6(j)) && (Function(i) ~=Function(j)))
Temp1 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i)];
Temp2 = [X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
Store4 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i);X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
end
if ((X1(i) == X1(j)) && (X2(i) == X2(j)) && (X3(i) == X3(j)) && (X4(i) == X4 (j)) && (X5(i) ~= X5(j)) && (X6(i) == X6(j)) && (Function(i) ~=Function(j)))
Temp1 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i)];
Temp2 = [X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
Store5 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i);X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
end
if ((X1(i) == X1(j)) && (X2(i) == X2(j)) && (X3(i) == X3(j)) && (X4(i) == X4 (j)) && (X5(i) == X5(j)) && (X6(i) ~= X6(j)) && (Function(i) ~=Function(j)))
Temp1 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i)];
Temp2 = [X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
Store6 = [X1(i) X2(i) X3(i) X4(i) X5(i) X6(i);X1(j) X2(j) X3(j) X4(j) X5(j) X6(j)];
end
end
end
Store = [Store1;Store2;Store3;Store4;Store5;Store6];
This is code that works under the boolean algebra toolbox environment. The output shuuld display a truth table and a complete test set. But there is an error at line 108. I don't know how to fix it. Can someone help me to fix it?
  1 Comment
Walter Roberson
Walter Roberson on 25 Mar 2014
I'm not going to try to debug that. Use variable names that are less confusing than x1 being different than X1 . Naming a variable "Function" is a bad idea as well; it is going to confuse people as people know that "function" is a reserved word.
Any program that has "clear all" in it is broken. If you want to make sure the workspace has nothing in it then use a function.

Sign in to comment.

Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!