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

1 vue (au cours des 30 derniers jours)
DIJESH
DIJESH le 27 Mai 2014
Commenté : DIJESH le 27 Mai 2014
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?

Réponse acceptée

rifat
rifat le 27 Mai 2014
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 commentaire
DIJESH
DIJESH le 27 Mai 2014
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'?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Function Handles dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by