How can I solve problem regarding subscript indices in for loop?

Hello Matlab users,
I get error massage, when I run the program.
Subscript indices must either be real positive integers or logicals.
Error in Test_2017_02_14 (line 82) clipping(end,:) = clipping(end,:)*1/2;
here is my code:
radius_max = 3200;
angle = 0:(2*pi/6):2*pi;
radius = [0 690 1390 1990 2490 2890];
r_m = [(1/2 * (radius+[0 radius(1:end-1)])) radius_max];
[angle_mat,radius_mat]=meshgrid(angle,radius);
[X,Y] = pol2cart(-(angle_mat)+pi/2,radius_mat);
surface = 1/4*pi*(([radius_mat(2:end,:);ones(1,length(angle))*(2*radius_max-radius(end))]+ radius_mat).^2-([radius_mat(1,:);radius_mat(1:end-1,:)]+radius_mat).^2)
/(length(angle)-1);
angle_fine = 0:(2*pi/60):2*pi;
laf = length(angle_fine);
radius_fine = 0:10:radius_max;
[angle_fine_mat,radius_fine_mat] = meshgrid(angle_fine,radius_fine);
[X_fine,Y_fine] = pol2cart(-(angle_fine_mat)+pi/2,radius_fine_mat);
surface_fine = 1/4*pi*(([radius_fine_mat(2:end,:);radius_fine_mat(end,:)]+radius_fine_mat).^2-([radius_fine_mat(1,:);radius_fine_mat(1:end-1,:)]+radius_fine_mat).^2) /(laf-1);
angle_ex = [2/9 1/2 5/6 7/6 3/2 16/9]*pi;
radius_ex = 2075;
[angle_ex_mat,radius_ex_mat]=meshgrid(angle_ex,radius_ex);
[X_ex,Y_ex] = pol2cart(angle_ex_mat-pi/2,radius_ex_mat);
angle_ufine = 0:(2*pi/600):2*pi;
radius_ufine = 0:2.5:radius_max;
[angle_ufine_mat,radius_ufine_mat]=meshgrid(angle_ufine,radius_ufine);
[X_ufine,Y_ufine] = pol2cart(-(angle_ufine_mat)+pi/2,radius_ufine_mat);
[~,index_a] = intersect(angle_ufine,angle);
[~,index_r] = intersect(radius_ufine,r_m);
angle_e = 0:(2*pi/6):6*pi;
radius_e = [radius radius_max];
[angle_mat_e,radius_mat_e]=meshgrid(angle_e,radius_e);
angle_fine_e = 0:(2*pi/600):6*pi;
radius_fine_e = 0:2.5:radius_max;
[angle_fine_mat_e,radius_fine_mat_e] = meshgrid(angle_fine_e,radius_fine_e);
radius_flow = [0 0.2 0.4 0.6 0.8 0.9 1]*radius_max;
flow_left = [0.058; 0.0603; 0.080; 0.119; 0.138; 0.124; 0];
flow_right = [0.058; 0.063; 0.079; 0.099; 0.104; 0.096; 0];
FL = transpose(spline(radius_flow,flow_left,radius_fine));
FR = transpose(spline(radius_flow,flow_right,radius_fine));
flow_fine(:,1:(laf-1)/2) = repmat(FL,1,(laf-1)/2)+(repmat(FR,1,(laf-1)/2)-repmat(FL,1,(laf-1)/2)).*(angle_fine_mat(:,1:(laf-1)/2)/pi);
flow_fine(:,(laf+1)/2:laf) = repmat(FR,1,(laf+1)/2)+(repmat(FL,1,(laf+1)/2)-repmat(FR,1,(laf+1)/2)).*((angle_fine_mat(:,(laf+1)/2:laf)-pi)/pi);
flow_fine = circshift(flow_fine(:,1:end-1),round(laf*(-110)/360),2);
flow_fine = [flow_fine flow_fine(:,1)];
index = 1:(laf-1)/6:laf;
flowXsurf = flow_fine.*surface_fine;
for i = 1:6
r_l = (i>1)*1/2*(radius(i)+radius((i>1)*(i-1)+(i==1)));
r_h = (i<6)*1/2*(radius(i)+radius((i<6)*(i+1)+(i==6))) + (i==6)*radius_max;
clipping = flowXsurf(find(radius_fine==r_l):find(radius_fine==r_h),:);
clipping = [clipping(:,end-find(angle_fine==pi/6)+1:end-1)...
clipping(:,1:end-find(angle_fine==pi/6)+1)];
if i>1
clipping(1,:) = clipping(1,:)*1/2;
end
if i<6
clipping(end,:) = clipping(end,:)*1/2;
end
clipping(:,index) = clipping(:,index)*1/2;
for j = 1:6
flow(i,j) = sum(sum(clipping(:,index(j):index(j+1))))/surface(i,j);
end
end
flow = [flow flow(:,1)];
Thank you in advance.

6 Comments

Subscript indices must either be real positive integers or logicals.
Error in Test_2017_02_14 (line 82)
clipping(end,:) = clipping(end,:)*1/2;
Or your clipping is empty?
Are you sure with the line number of error? According to me that line has no issues:
clipping(end,:) = clipping(end,:)*1/2;
It has nothing to do with indices.
You can't index to empty variable.
"You can't index to empty variable."
With an empty index you can:
>> A = [];
>> A([])
ans = []

Sign in to comment.

 Accepted Answer

radius_fine = 0:10:radius_max;
I think, I got it. I tried as bellows: radius_fine = 0:1:radius_max; radius_fine = 0:5:radius_max;
Then it works. I got no errr Massage.
Tank you guys for your afford.

More Answers (0)

Products

Release

R2017b

Community Treasure Hunt

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

Start Hunting!