我正在使用单元格管理我正在处理的一些东西中的数据.我希望能够做到这样的事情:
A = cellfun( @(X)( randn( 5,5 ) ), cell( 5,1 ), 'UniformOutput', 0 );
B = cellfun( @(X)( randn( 5,5 ) ), cell( 5,1 ), 'UniformOutput', 0 );
%#
%# Each of the following would fail if cell member dimensions
%# don't match up
%#
%# matrix sums for each cell entry
%# C = A + B;
C = cellfun( @(X,Y)( X + Y ), A, B, 'UniformOutput', 0 );
%#
%# direct/hadamard product
%# D = A …Run Code Online (Sandbox Code Playgroud) 我正在为MATLAB/Octave中的一些VHDL代码开发一个验证工具.因此,我需要生成"真正"溢出的数据类型:
intmax('int32') + 1
ans = -2147483648
Run Code Online (Sandbox Code Playgroud)
稍后,如果我可以定义变量的位宽,那将会很有帮助,但现在这不是那么重要.
当我构建一个类似C的例子时,变量增加直到它小于零,它会永远旋转:
test = int32(2^30);
while (test > 0)
test = test + int32(1);
end
Run Code Online (Sandbox Code Playgroud)
我尝试的另一种方法是自定义"溢出" - 例程,每次更改数字后都会调用它.这种方法非常缓慢,不实用,根本不适用于所有情况.有什么建议?
如果我有一个数组(在运行时之前长度未知),有没有办法调用一个函数,并将数组的每个元素作为一个单独的参数?
像这样:
foo = @(varargin) sum(cell2mat(varargin));
bar = [3,4,5];
foo(*bar) == foo(3,4,5)
Run Code Online (Sandbox Code Playgroud)
上下文:我有一个n-d数组的索引列表Q.我想要的是什么Q(a,b,:),但我只有[a,b].由于我不知道n,我不能只是硬编码索引.
matlab operators multidimensional-array splat matrix-indexing