MATLAB: Using operators (+,-,*,/) in variables MATLABoperators 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; Best Answer Use str2fun to change your string into a function handle. Note that the string content must be a valid matlab function name ( '+' is)op = '+';a = 1;b = 2;opfn = str2fun(op);c = opfn(a, b);There is no way to have itc = a opfn b; %can't be done in matlab Related SolutionsMATLAB: How to add a string output to this function function [op,op1] = operation( A,B )X=[A+B; A-B; A/B; A*B; B-A; B/A;];o={'plus','minus','div','prod','iminus','idiv'}ii=randperm(6)op1=o{ii(1)};Y=X(ii,:);if Y(1,1)>0 && Y(1,1)==int16(Y(1,1)) op=Y(1,1);else [op,op1]=operation(A,B);endend MATLAB: Enable/disable parameter in embedded matlab function function y=fcn(a,b,c,d)if d==1 y=aelseif d==2 y=a+belseif d==3 y=a+b+cend%orfunction y=fcn(a,b,c,d)v=[a b c];y=sum(v(1:d)) Related QuestionHow is it possible to tell if systems are linear, non-linear or time-invariantElse if Question with functionHow to use two logical operation inside a if conditionHow to create a matrix composed of some data in another matrixIs there an equivalent function to the “kron(x,y)” that uses subtraction as its operation rather than multiplicationFunction with variable number of input arguments
Best Answer