Search code examples
matlabscilabconverters

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


I am very new to Scilab, but so far have not been able to find an answer (either here or via google) to my question. I'm sure it's a simple solution, but I'm at a loss. I have a lot of MATLAB scripts I wrote in grad school, but now that I'm out of school, I no longer have access to MATLAB (and can't justify the cost). Scilab looked like the best open alternative. I'm trying to convert my .m files to Scilab compatible versions using mfile2sci, but when running the mfile2sci GUI, I get the error/message shown below. Attached is the original code from the M-file, in case it's relevant.

I Searched Stack Overflow and companion sites, Google, Scilab documentation.

The M-file code follows (it's a super basic MATLAB script as part of an old homework question -- I chose it as it's the shortest, most straightforward M-file I had):

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');

The command used (and results) follow:

--> 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 ******

Solution

  • To convert the foo.m file one has to enter

     mfile2sci <path>/foo.m
    

    where stands for the path of the directoty where foo.m is. The result is written in /foo.sci