Woooow.. I solved it. You must define a_p as an empty vector before allocating a vector to it as follow. since it's dimension is changing continuously.
for j=1:J
a_p=[]
switch J
case 1
a_p = [3,4,5,9,10];
case 2
a_p = [1,2,6,7,8,14,15];
case 3
a_p = [11,12,13,19,20];
case 4
a_p = [16,17,18,25];
case 5
a_p = [21,22,23,24];
otherwise
% error(...) ?
% a_p = [...] ?
end
end
if true
% code
end
But after a few seconds running, the following message appears. what should I do?
''The working dimension was selected automatically, is variable-length, and has length 1 at run-time. This is not supported. Manually select the working dimension by supplying the DIM argument.''