using operators (+,-,*,/) in variables
Show older comments
Hi, if i need to config for + to be 'op' for example how can i then use it as an actual + further down the code?
example
op='+';
a=1;
b=2;
c=a(+ as op)b;
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 3 Dec 2014
You can create this function
function y=op(a,b,operator)
if operator=='+'
y=a+b
elseif operator=='-'
y=a-b
elseif operator=='/'
y=a/b
elseif operator=='*'
y=a*b
end
% And call it
y=op(5,6,'+')
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!