matlab 源码阅读

来源:互联网 发布:淘宝网1元秒杀在哪里找 编辑:程序博客网 时间:2024/06/05 04:01

源码面前,了无秘密。

You can read and edit the source code for M-file functions that ship with MATLAB; the only way to read and edit the built-in functions like FFT is to get a job with The MathWorks. We don’t distribute the built-in source code for MATLAB.

一般 matlab 开源的源码实现均十分的精简和完备,是学习 matlab 的极佳素材。

1. trace:矩阵的迹

function t = trace(A)if ~ismatrix(A) || size(A,1)~=size(A,2)  error(message('MATLAB:trace:square'));endt = full(sum(diag(A)));

2. isOctave

检测是否运行的是 octave 版本(语法与 matlab 接近,但 octave 是开源免费的);

function result = isOctave()    result = exists('OCTAVE_VERSION') ~= 0;end

3. squeeze

function b = squeeze(a)    siz = size(a);    siz(siz == 1)    = [];    siz = [siz, ones(1, 2-length(siz))];          % 确保 siz 至少为二维;    b = reshape(a, siz);end
0 0
原创粉丝点击