How do i add all the values which i get using eval function?
Show older comments
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
for jj=1:numel(a)
string='f(jj)*cos(jj)';
eval(string)
end
in this code i am getting several values for string. I have to add all those values. can anyone help?
Accepted Answer
More Answers (1)
rifat
on 27 May 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
sum=0;
for jj=1:numel(a)
string='f(jj)*cos(jj)';
sum=sum+eval(string);
end
Categories
Find more on Discriminant Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!