Looping for input data

13 views (last 30 days)
Moustafa Abedel Fattah
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: ');
R(i)=input('Enter Raduis: ');
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');

Answers (1)

Walter Roberson
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: ');
R(i)=input('Enter Raduis: ');
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!