How is a global matrix different?

妖精的绣舞 提交于 2019-12-08 06:07:18

问题


This computes fine:

spike(waves0);

But this surprisingly doesn't:

toArff(@spike)
error: A(I): Index exceeds matrix dimension.
error: called from:
error:   /Users/simpatico/mlr/spike.m at line 4, column 7
error:   /Users/simpatico/mlr/toArff.m at line 4, column 16

function toArff = toArff(features)

        global waves0;
        spike0 = features(waves0);
        true = zeros(size(waves0)(1), 1);
        P = [spike0 true];

end

回答1:


You need to declare waves0 as global in the base workspace first.

Alternatively, you can use the waves0 = evalin('base', 'waves0'); to fetch the value from the base workspace.

Note that none of these options are considered to be good practice, since it gives rise to exactly the sort of issue you're seeing, amongst others. It would be much better to pass waves0 in as an input parameter.



来源:https://stackoverflow.com/questions/8414283/how-is-a-global-matrix-different

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!