MATLAB: What does ” Subscript indices must either be real positive integers or logicals” mean and how to fix it

subscript indices

clear
clc
close all
%Define Variables
v1=0.3;
v2=0.3;
E1=200e9;
E2=200e9;
d1=38;
d2=70;
L=50;
F=450;
z=[0.025,0.25,2.5];
%Perform Calculations
b=sqrt(((2*F/pi*L)*(1-(v1^2))/(E1+(1-(v2^2))/E2))/((1/d1)+(1/d2)));
Pmax=(2*F)/(pi*b*L);
a1=z/b;
a2=sqrt(1+(z.^2/b^2));
%Principal Stresses (Outputs)
sigmax=-2*v2*Pmax(sqrt(1+(z.^2/b^2))-(z/b))
sigmay=-Pmax*((2-(1/(1+(z.^2/b^2)))*sqrt(1+(z.^2)/b^2)-(2*(z/b))))
sigmaz=-Pmax/(sqrt(1+(z.^2/b^2)))
Error message is:
Subscript indices must either be real positive integers or logicals.
Error in pstress (line 24)
sigmax=-2*v2*Pmax(sqrt(1+(z.^2/b^2))-(z/b))

Best Answer

Are you missing a division or multiplication sign after the 'Pmax'? Was this really supposed to be
sigmax=-2*v2*Pmax/(sqrt(1+(z.^2/b^2))-(z/b))
As it stands, MATLAB thinks you are trying to index into Pmax with the noninteger expression sqrt(1+(z.^2/b^2))-(z/b)