# Looping for input data

31 views (last 30 days)
Moustafa Abedel Fattah on 15 Jul 2015
Edited: Walter Roberson on 15 Jul 2015
I am a new user for matlab programing and I made the simple following program and I need to make a loop for intering data with index i as following:
% Length of variable x and the Number of Entered data n
x =0:10;
%===================================================
% Entered data
for i= 0:10
i=i+1;
x(i)=input('Enter measured point: ');
z(i)=input('Enter depth: ');
rho(i)=input('Enter density: ');
end
gz(i)=G*4*pi*R.^3/3.0*z*rho./(x.^2+z.^2).^1.5;
%===================================================
% Ploting the results
plot(x,gz(i),'r');

Walter Roberson on 15 Jul 2015
Edited: Walter Roberson on 15 Jul 2015
% Length of variable x and the Number of Entered data n
n = 11;
%===================================================
% Entered data
for i= 1:n
x(i)=input('Enter measured point: ');
z(i)=input('Enter depth: ');
rho(i)=input('Enter density: ');
end
gz = G*4*pi*R.^3/3.0.*z.*rho./(x.^2+z.^2).^1.5;
%===================================================
% Ploting the results
plot(x,gz,'r');
Assuming that you defined G before this.