MATLAB 到 Scilab 的转换:mfile2sci 错误 "File contains no instruction"

MATLAB to Scilab conversion: mfile2sci error "File contains no instruction"

我对 Scilab 非常 陌生,但到目前为止还没有找到我的问题的答案(无论是在这里还是通过 google)。我确定这是一个简单的解决方案,但我不知所措。我有很多在研究生院写的 MATLAB 脚本,但现在我已经离开学校,我无法再使用 MATLAB(并且无法证明成本合理)。 Scilab 看起来是最好的开放替代方案。我正在尝试使用 mfile2sci 将我的 .m 文件转换为 Scilab 兼容版本,但是当 运行 mfile2sci GUI 时,我得到如下所示的 error/message。附件是 M 文件的原始代码,以防相关。

我搜索了 Stack Overflow 和配套网站,Google,Scilab 文档。

M 文件代码如下(这是一个超级基本的 MATLAB 脚本,作为旧作业问题的一部分——我选择它是因为它是我拥有的最短、最直接的 M 文件):

Mmax = 15;
N = 20;
T = 2000;
%define upper limit for sparsity of signal
smax = 15;
mNE = zeros(smax,Mmax);
mESR= zeros(smax,Mmax);
for M = 1:Mmax
    aNormErr = zeros(smax,1);
    aSz = zeros(smax,1);
    ESR = zeros(smax,1);
for s=1:smax % for-loop to loop script smax times
    normErr = zeros(1,T); 
    vESR = zeros(1,T);
    sz = zeros(1,T);
    for t=1:T %for-loop to carry out 2000 trials per s-value
        esr = 0;
        A = randn(M,N); % generate random MxN matrix
        [M,N] = size(A);
        An = zeros(M,N);            % initialize normalized matrix
            for h = 1:size(A,2) % normalize columns of matrix A
                V = A(:,h)/norm(A(:,h));
                An(:,h) = V;
            end
        A = An; % replace A with its column-normalized counterpart
        c = randperm(N,s); % create random support vector with s entries
        x = zeros(N,1);    % initialize vector x
            for i = 1:size(c,2)
                val = (10-1)*rand + 1;% generate interval [1,10]
                neg = mod(randi(10),2); % include [-10,-1]
                    if neg~=0
                        val = -1*val;
                    end
                x(c(i)) = val; %replace c(i)th value of x with the nonzero value
            end
            y = A*x; % generate measurement vector (y)
            R = y;  
            S = []; % initialize array to store selected columns of A
            indx = []; % vector to store indices of selected columns
            coeff = zeros(1,s); % vector to store coefficients of approx.
            stop = 10; % init. stop condition
            in = 0; % index variable
            esr = 0;
            xhat = zeros(N,1); % intialize estimated x signal
            while (stop>0.5 && size(S,2)<smax)
                %MAX = abs(A(:,1)'*R);
                maxV = zeros(1,N);
                for i = 1:size(A,2)
                    maxV(i) = abs(A(:,i)'*R);
                end
                in = find(maxV == max(maxV));
                indx = [indx in];
                S = [S A(:,in)];
                coeff = [coeff R'*S(:,size(S,2))]; % update coefficient vector
                for w=1:size(S,2)
                    r = y - ((R'*S(:,w))*S(:,w)); % update residuals
                    if norm(r)<norm(R)
                        index = w;
                    end
                    R = r;
                stop = norm(R); % update stop condition
                end
        
                for j=1:size(S,2) % place coefficients into xhat at correct indices
                    xhat(indx(j))=coeff(j);
                end
            nE = norm(x-xhat)/norm(x); % calculate normalized error for this estimate
            %esr = 0;
            indx = sort(indx);
            c = sort(c);
                if isequal(indx,c)
                    esr = esr+1;
                end
            end
        vESR(t) = esr;    
        sz(t) = size(S,2);
        normErr(t) = nE;
    end

    %avsz = sum(sz)/T;
    aSz(s) = sum(sz)/T;
    %aESR = sum(vESR)/T;
    ESR(s) = sum(vESR)/T;
    %avnormErr = sum(normErr)/T; % produce average normalized error for these run
    aNormErr(s) = sum(normErr)/T; % add new avnormErr to vector of all av norm errors
end
% just put this here to view the vector
mNE(:,M) = aNormErr;
mESR(:,M) = ESR;
% had an 'end' placed here, might've been unmatched
mNE%reshape(mNE,[],Mmax)
mESR%reshape(mESR,[],Mmax)]
figure
dimx = [1 Mmax];
dimy = [1 smax];
imagesc(dimx,dimy,mESR)
colormap gray
strESR = sprintf('Average ESR, N=%d',N);
title(strESR);
xlabel('M');
ylabel('s');
strNE = sprintf('Average Normed Error, N=%d',N);
figure
imagesc(dimx,dimy,mNE)
colormap gray
title(strNE)
xlabel('M');
ylabel('s');

使用的命令(和结果)如下:

--> mfile2sci
 ans  =

    []

  ****** Beginning of mfile2sci() session ******
  File to convert: C:/Users/User/Downloads/WTF_new.m
  Result file path: C:/Users/User/DOWNLO~1/
  Recursive mode: OFF
  Only double values used in M-file: NO
  Verbose mode: 3
  Generate formatted code: NO
  M-file reading...
  M-file reading: Done
  Syntax modification...
  Syntax modification: Done
  File contains no instruction, no translation made...
  ****** End of mfile2sci() session ******

去掉每行开头的````,转换会正常进行吗?。但是,不要指望获得工作的 .sci 文件,因为 m2sci 转换器(对我来说)仍然是一个实验工具!

要转换 foo.m 文件,必须输入

 mfile2sci <path>/foo.m

where代表foo.m所在目录的路径。结果写在/foo.sci