I'm interested in defining a new control statement in MATLAB. Matlab already has loop definitions such as for
, parfor
, if
, and while
but I would like define a new control statement. Is this possible in MATLAB?
Asked
Active
Viewed 85 times
1

aplassard
- 759
- 3
- 10
-
5I don't think so. Which one would you want? I sometimes miss a `do`...`while`: run a statement at least once and _then_ check wether to repeat or nor – Luis Mendo Feb 13 '15 at 22:22
-
What I'm currently interested in doing is a loop similar to parfor where I can just submit all of loops to a queue for my local cluster. – aplassard Feb 13 '15 at 22:23
-
3I don't think this is possible. You could of course write a normal function and supply a function handle and range for the parameter. – hbaderts Feb 14 '15 at 08:10
-
I think that this is impossible, it most likely would require a lot of support from the JIT compiler. However, you should try to define this as function instead. This is not really different from how this is normally done in any language. Just look at the `for_each` loop in c++ for example. – patrik Feb 14 '15 at 12:07
-
1If you want to know how to submit MATLAB jobs to a cluster, you should better ask that. Your current question will certainly only have the answer: No. Would you even know any other programming language where you could define your own *control statements*? – knedlsepp Feb 14 '15 at 18:34
1 Answers
1
What I'm currently interested in doing is a loop similar to parfor where I can just submit all of loops to a queue for my local cluster.
I don't think you can easily extend/modify the syntax of Matlab. It's not that flexible and I have never seen it. Although I do not know that for sure, I recommend asking Mathworks for an ultimate answer (most probably no).
However why not programming in C / Java (or any other language that does implement the control statements you like) and then combining them with Matlab?
C and Java are especially easy to combine with Matlab, but everything else in a dll should work. And from the dll you can call Matlab code, so hybrid programming (mixing Matlab and something else) is possible.
See also:

Community
- 1
- 1

NoDataDumpNoContribution
- 10,591
- 9
- 64
- 104
-
I'm totally capable of writing code to submit jobs to my cluster without this sort of extension, I'm just curious if there was a more "interesting" way to do it. – aplassard Feb 14 '15 at 22:56
-
@aplassard Maybe you should kind of show in another question how you do it currently and then ask what is the most efficient/easiest way to do the same in Matlab. I'm still not sure I understand what exactly you want to have. – NoDataDumpNoContribution Feb 15 '15 at 10:39