필터 지우기
필터 지우기

Looping for input data

조회 수: 4 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by