Looping for input data

10 ビュー (過去 30 日間)
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2015 年 7 月 15 日
編集済み: Walter Roberson 2015 年 7 月 15 日
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');

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 7 月 15 日
編集済み: Walter Roberson 2015 年 7 月 15 日
% 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.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by