how do i use the values read by the eval function in other formulas?

조회 수: 1 (최근 30일)
DIJESH
DIJESH 2014년 5월 27일
댓글: DIJESH 2014년 5월 27일
prompt = {'Enter the forces(kN): '};
title = 'Environmental forces';
answer = inputdlg(prompt,title);
f = str2num(answer{:});
for ii=1:numel(f)
eval(sprintf('f%d = %f\n',ii,f(ii)))
end
prompt1 = {'Enter the respective angles: '};
title1 = 'Angle w.r.t x-axis';
answer1 = inputdlg(prompt1, title1);
a = str2num(answer1{:});
for jj=1:numel(a)
eval(sprintf('a%d = %f\n',jj,a(jj)))
end
The code above would read the forces and their respective angles and assign the variables automatically. I want to find the horizontal component. i.e. f*cos(a).. How do i do it?

채택된 답변

rifat
rifat 2014년 5월 27일
prompt = {'Enter the forces(kN): '};
title = 'Environmental forces';
answer = inputdlg(prompt,title);
f = str2num(answer{:});
for ii=1:numel(f)
eval(sprintf('f%d = %f\n',ii,f(ii)))
end
prompt1 = {'Enter the respective angles: '};
title1 = 'Angle w.r.t x-axis';
answer1 = inputdlg(prompt1, title1);
a = str2num(answer1{:});
for jj=1:numel(a)
eval(sprintf('a%d = %f\n',jj,a(jj)))
end
disp('shows the f*cos(a)');
for jj=1:numel(a)
string=['f(jj)*cos(a(jj))'];
eval(string)
end
  댓글 수: 1
DIJESH
DIJESH 2014년 5월 27일
can u please explain how to add the values which is evaluated at the end? i mean wat if i have to add the all the values in the variable 'string'?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Handles에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by