Disable MATLAB's implicit expansion

后端 未结 2 1189
轮回少年
轮回少年 2021-01-05 17:42

Recently, in R2016b a feature was added to MATLAB, which is causing a lot of headaches in the school where I teach.

Nowadays formulae, which traditionally would be c

2条回答
  •  滥情空心
    2021-01-05 18:10

    As mentioned by @PhelypeOleinik, this is (since R2016b) a core part of the language, and for good reasons, as detailed in the blog post referred to.

    However, if you REALLY want to disable it...

    1. Make a folder somewhere on your path, called @double.
    2. In this folder, make a file plus.m.

    In the file, put something like the following:

    function out = plus(in1, in2)
        % do some things here
        out = builtin('plus', in1, in2)
    

    Where I have a comment above, you can put whatever code you like: which could include code that checks the inputs for the "size-compatibility" rules you want, and errors if it doesn't meet them.

    Do something similar for the functions minus, times, ldivide, rdivide, power, and other functions you want to modify.

    PS please don't actually do this, the developers worked very hard to implement implicit expansion, and they'll cry if they see you disabling it like this...

提交回复
热议问题