-
-
Save muddana/1222462 to your computer and use it in GitHub Desktop.
An attempt at Ruby type conditional expression support in MATLAB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%/ | |
% Developer : Srinivas Muddana ([email protected]) | |
% All code (c)2012 Srinivas Muddana. all rights reserved | |
% | |
% do a = a*-1 if(a<0); | |
% can add a ternary operator too.?? | |
function do(varargin) | |
%expr = size(2*length(varargin) -1) ; | |
expr = ''; | |
for(ii = 1:length(varargin)) | |
expr = [expr ' ' varargin{ii}]; | |
end | |
[a,b, c, d] = regexp(expr, '(.*)if(.*)'); | |
bodyIndexRange = c{1}(1,:); | |
ifBodyStr = expr(bodyIndexRange(1):bodyIndexRange(2)); | |
condIndexRange = c{1}(2,:); | |
ifCondStr = expr(condIndexRange(1):condIndexRange(2)); | |
code = ['if(' ifCondStr ')' char(10) ... | |
ifBodyStr ';' char(10)... | |
'end' char(10)]; | |
evalin('caller', code); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment