Azzera filtri
Azzera filtri

Looping for input data

4 visualizzazioni (ultimi 30 giorni)
Moustafa Abedel Fattah
Moustafa Abedel Fattah il 15 Lug 2015
Modificato: Walter Roberson il 15 Lug 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');

Risposte (1)

Walter Roberson
Walter Roberson il 15 Lug 2015
Modificato: Walter Roberson il 15 Lug 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by