MATLAB: Error code troubleshooting

error

I have just begun using Matlab and have encountered an issue with the code I am writing. When I evaluate the cell I get the error;
"??? In an assignment A(I) = B, the number of elements in B
and
I must be the same."
This error only appears when I don't comment out lines 31, 35, and 39. The other strange part is the code evaluates and writes all 71738 points of data to Fdx, Fdy, and Fdz, but will not evaluate any further.
When those lines are commented out the cell evaluates and the plot is made. However I need to get the code to work in order to complete the plot accurately.
Here is the code;
clc
%Define Constants
rhoa = 1.4651; %kg/m^3 Density of air at 22C
rhow = 997.77; %kg/m^3 Density of Water
D = (50*10^-6); %m Diameter of droplet
dyn = (1.8031*10^-5); %kg/m-s Dynamic Viscosity of air
g = -9.81; %m/s^2 Gravity
A = pi*(D/2)^2; %m^2 Cross Sectional Area of droplet
t = .05; %sec Time
%Initialize Variables
Rex = 0; %Reynolds' Number x-direction
Cdx = 0; %Coefficent of Drag x-direction
Fdx = 0; %Drag Force x-direction
Rey = 0; %Reynolds' Number y-direction
Cdy = 0; %Coefficent of Drag y-direction
Fdy = 0; %Drag Force y-direction
Rez = 0; %Reynolds' Number z-direction
Cdz = 0; %Coefficent of Drag z-direction
Fdz = 0; %Drag Force z-direction
X = 0; %Postion of droplet x-direction
Y = 0; %Postion of droplet y-direction
Z = 3; %Postion of droplet z-direction
Rex = ((rhoa)*(D)*abs((Vx)))/(dyn);
Cdx = (24./Rex)+((2.6.*(Rex/5))./(1+(Rex./5).^1.52))+((.411.*(Rex./263000).^-7.94)./(1+(Rex./263000.^-8)))+((Rex.^.8)./461000);
Fdx = Cdx.*.5*rhow*A.*Vx.^2;
Rey = ((rhoa)*(D)*abs((Vy)))/(dyn);
Cdy = (24./Rey)+((2.6.*(Rey./5))./(1+(Rey./5).^1.52))+((.411.*(Rey./263000).^-7.94)./(1+(Rey./263000.^-8)))+((Rey.^.8)./461000);
Fdy = Cdy*.5*rhow*A.*Vy.^2;
Rez = ((rhoa)*(D)*abs((Vz)))/(dyn);
Cdz = (24./Rez)+((2.6.*(Rez./5))./(1+(Rez./5).^1.52))+((.411.*(Rez./263000).^-7.94)./(1+(Rez./263000.^-8)))+((Rez.^.8)./461000);
Fdz = Cdz*.5*rhow*A.*Vz.^2;
for k = 2:347
X(k) = X(k-1)+(Vx(k-1)*t)-(Fdx*t^2);
Y(k) = Y(k-1)+(Vy(k-1)*t)-(Fdy*t^2);
Z(k) = Z(k-1)+(Vz(k-1)*t)+(.5*g*t^2)-(Fdz*t^2);
end
X = reshape(X,347,1);
Y = reshape(Y,347,1);
Z = reshape(Z,347,1);
plot3(X,Y,Z,'.-b');
grid on;
xlabel('Distance West to East (m)')
ylabel('Distance South to North (m)')
zlabel('Height (m)')
title('50 micron Droplet Path')
Any help is appreciated.

Best Answer

Those would not be the lines that have the error messages. Those would, though, define Fdx, Fdy, and Fdz to be vectors. Then you use them as full vectors in (e.g.)
X(k) = X(k-1)+(Vx(k-1)*t)-(Fdx*t^2);
so the right hand side is going to give a vector result. A vector result cannot be stored into a single array element.
I don't know. Perhaps you want
X(k) = X(k-1)+(Vx(k-1)*t)-(Fdx(k-1)*t^2);
And perhaps you don't. You might be needing to total across all the Fdx entries or something like that (I do not happen to know the math behind the problem you are trying to solve.)