Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am Trying to convert a MATLAB code to C++ using MATLAB coder but this error apears:

Error indenting generated C code

The error points to the name of the function itself and has no more explanations in it. can someone tell me what is this error? here is the function i want to conver:

function [Report_Clustered,ClusterCounter_new]=InitClusterGenerator_test(Report_In,~,FreqEpsilon,DegreeEpsilon,~,ClusterCounter_old, BlockCount, Report_old)

Report_M = zeros(size(Report_In,1),size(Report_In,2),4);
for i=1:size(Report_In,1)
    for j=1:size(Report_In,2)
        Report_M(i,j,1)=Report_In(i,j,1);
        Report_M(i,j,2)=Report_In(i,j,2);
        Report_M(i,j,3)=0; % Cluster number that the point belongs to.
        Report_M(i,j,4)=0;
Report_In{i,j} 
    end
end
ClusterCounter = 0;
for i=1:size(Report_M,1)
    for j=1:size(Report_M,2)
        if (Report_M(i,j,3) == 0)
            ClusterCounter = ClusterCounter + 1;
            Report_M(i,j,3) = ClusterCounter;
            for ii=1:size(Report_M,1)
                for jj=1:size(Report_M,2)
                    if (Report_M(ii,jj,3) == 0)
                        if (abs(Report_M(i,j,1)-Report_M(ii,jj,1))<FreqEpsilon &&...
                        (abs(Report_M(i,j,2)-Report_M(ii,jj,2)) <DegreeEpsilon ||...
                        abs(-360 + Report_M(i,j,2)-Report_M(ii,jj,2)) <DegreeEpsilon ||...
                        abs(360 + Report_M(i,j,2)-Report_M(ii,jj,2)) <DegreeEpsilon))
                            Report_M(ii,jj,3) = ClusterCounter;
                        end
                    end
                end
            end
        end
    end
end    


if (BlockCount> 20 && ClusterCounter<4)
    warning = 1;
end



        ClusterCounter_new = ClusterCounter;

        %clear Report_new;
        flag = 0;

        Report_new = zeros(ClusterCounter,size (Report_M, 2),4);

        index = zeros(1, ClusterCounter_new);
        for i = 1: size (Report_M, 1)
            for j = 1: size (Report_M, 2)
                for k = 1: ClusterCounter_new
                    if (Report_M(i,j,3) == k)
                        index(1,k) = index(1,k) + 1;
                        Report_new(k,index(1,k), 1:3) = Report_M(i,j,1:3);
                        flag = flag + 1;
                    end
                end

            end
        end



        for j = 1: size (Report_new, 2)
            for i = 1: size (Report_new, 1)
                if (Report_new(i,j,1) == 0)
                    Report_new(i,j,1:3) = Report_new(i,1,1:3);
                end
            end
        end

        %Report_new = Report;


        MedoidF_old = zeros(1, size(Report_old,1));
        MedoidA_old = zeros(1, size(Report_old,1));


        for i=1:size(Report_old,1)
            SumF = 0;
            SumA = 0;
            MinAngle = 361;
            MaxAngle = -1;
            for j=1:size(Report_old,2)
                SumF = SumF + Report_old(i,j,1);
                SumA = SumA + Report_old(i,j,2);
                if Report_old(i,j,2) > MaxAngle
                    MaxAngle = Report_old(i,j,2);
                elseif Report_old(i,j,2) < MinAngle
                    MinAngle = Report_old(i,j,2);
                end
            end
            MedoidF_old(1, i) = SumF/size(Report_old,2);
            if (MaxAngle - MinAngle) > 350
                MedoidA_old(1, i) = 0;
            else
                MedoidA_old(1, i) = SumA/size(Report_old,2);
            end
        end


        MedoidF_new = zeros(1, size(Report_new,1));
        MedoidA_new = zeros(1, size(Report_new,1));


        for i=1:size(Report_new,1)
            SumF = 0;
            SumA = 0;
            MinAngle = 361;
            MaxAngle = -1;
            for j=1:size(Report_new,2)
                SumF = SumF + Report_new(i,j,1);
                SumA = SumA + Report_new(i,j,2);
                if Report_new(i,j,2) > MaxAngle
                    MaxAngle = Report_new(i,j,2);
                elseif Report_new(i,j,2) < MinAngle
                    MinAngle = Report_new(i,j,2);
                end
            end
            MedoidF_new(1, i) = SumF/size(Report_new,2);
            if (MaxAngle - MinAngle) > 350
                MedoidA_new(1, i) = 0;
            else
                MedoidA_new(1, i) = SumA/size(Report_new,2);
            end
        end

        TempCluster = zeros(1, size(Report_new, 1));
        CurrentCluster = ClusterCounter_old;        


        for i = 1: 1: size(Report_new,1)
            for j = 1: 1: size(Report_old,1)
                if (abs(MedoidF_old(1,j)-MedoidF_new(1,i))<FreqEpsilon &&...
                        (abs(MedoidA_old(1,j)-MedoidA_new(1,i))<DegreeEpsilon ||...
                        abs(360 + MedoidA_old(1,j)-MedoidA_new(1,i))<DegreeEpsilon ||...
                         abs(-360 + MedoidA_old(1,j)-MedoidA_new(1,i))<DegreeEpsilon))      %%if the new cluster is the rest of an old cluster use the old one's index for it
                    TempCluster(1,i) = Report_old(j,1,3);
                end
            end

            %%this part is for seperating the clusters which where in the collision state in the past time



            if (TempCluster(1,i)>0) %%if the new cluster is one of the old ones the index should be set
                for j = 1:1:size(Report_new, 2)
                    Report_new(i,j,3) = TempCluster(1,i);
                    Report_new(i,j,4) = 1;% Alive
                end
            else    %%first search if the new cluster is a part of a newly found cluster found before this one
                for j = 1: 1: i-1
                    if (abs(MedoidF_new(1,j)-MedoidF_new(1,i))<FreqEpsilon &&...
                            (abs(MedoidA_new(1,j)-MedoidA_new(1,i))<DegreeEpsilon ||... 
                            abs(360 + MedoidA_new(1,j)-MedoidA_new(1,i))<DegreeEpsilon ||...
                            abs(-360 + MedoidA_new(1,j)-MedoidA_new(1,i))<DegreeEpsilon))       %%if the new cluster is the rest of an old cluster use the old one's index for it
                        TempCluster(1,i) = Report_new(j,1,3);
                    end
                end
            end

            if (TempCluster(1,i)>0) %%if the new cluster is one of the old ones the index should be set
                for j = 1:1:size(Report_new, 2)
                    Report_new(i,j,3) = TempCluster(1,i);
                    Report_new(i,j,4) = 1;% Alive
                end
            else    %%new cluster is just began so it needs a new index
                CurrentCluster = CurrentCluster + 1;
                ClusterCounter_new = CurrentCluster;
                TempCluster(1,i) = CurrentCluster;
                for j = 1:1:size(Report_new, 2)
                    Report_new(i,j,3) = TempCluster(1,i);
                    Report_new(i,j,4) = 1; % Alive
                end
            end

        end


        NewClusters = zeros(1, size (Report_new, 1));
        for i = 1: size(Report_new, 1)
            NewClusters (1,i) = Report_new(i,1,3);
        end

        OldClusters = zeros(1, size (Report_old, 1));
        OldClustersLine = zeros(1, size (Report_old, 1));
        for i = 1: size(Report_old, 1)
            OldClusters (1,i) = Report_old(i,1,3);
            OldClustersLine (1, i) = i;
        end


        NumberOfDead = 0;
        %clear AddDead;
        AddDead = zeros (16,size(Report_new, 2),4);
        if (BlockCount>10)
        for i = 1: size (OldClusters, 2)
            IsDead = 1;
            for j = 1: size (NewClusters, 2)
                if OldClusters(1, i) == NewClusters(1,j)
                    IsDead = 0;
                end
            end
            if (IsDead == 1)
                NumberOfDead = NumberOfDead + 1;
                %clear TempLine;
                TempLine = zeros(1, size(Report_old,2), 4);
                TempLine(1,:,1:3) = Report_old(OldClustersLine(1, i),:,1:3);
                for k= 1: size(TempLine, 2)
                    TempLine(1,k,4) = 0;    % Dead
                end
                TempSize = size(TempLine, 2);
                Thresh = size(Report_new, 2);

                if (TempSize >= Thresh)
                    AddDead (NumberOfDead, 1:Thresh, 1:4) = TempLine(1,1:Thresh, 1:4);
                else
                    for l = 1: Thresh-TempSize
                        TempLine(1, TempSize+l, 1:4) = TempLine(1, TempSize, 1:4);
                    end
                    AddDead (NumberOfDead, 1:Thresh, 1:4) = TempLine(1,1:Thresh, 1:4);
                end
            end
        end
        xR = size (Report_new,1);
        if (NumberOfDead == 0)
            Report_Clustered = zeros (size(Report_new,1),size(Report_new,2),size(Report_new,3));
        else
            Report_Clustered = zeros (size(Report_new,1) + NumberOfDead,size(Report_new,2),size(Report_new,3));
        end
        Report_Clustered (1:size(Report_new,1), :, :) = Report_new(:,:,:);
        for i = 1: NumberOfDead
            Report_Clustered(xR + i, :) = AddDead(i, :);
        end


end

and I'm using matlab 2012a Tnx.

share|improve this question
    
Could you paste the exact error message with a small repro code? Also, which version of matlab are you using? –  Lokesh A. R. Feb 25 '14 at 11:54
3  
Problem solved. this error must be something about the matlab not being able to overwrite the files built in the mex making process. you should quit matlab, delete the files made by coder and try running the coder again. ty @LokeshA.R. anyway. –  Brokenlink Feb 25 '14 at 12:17
    
Perhaps, you could add the solution too. It will help others who have the same error message. –  Lokesh A. R. Feb 25 '14 at 16:40
    
the solution is simple, the problem is when you build, say .mex file from your matlab code using coder and run it, when you want to make changes in the matlab code and build it again you may face this error. I think this situation only happens when your .mex code stops working with an error. I think MATLAB somehow do not closes the .mex file it is running so you can not rebuild it. in this situation if you try to delete the .mex file from workspace you would notice that it says permission is denied, so you just have to close matlab and delete .mex file and run matlab again. hope it's helpful. –  Brokenlink Feb 26 '14 at 7:34
    
@Brokenlink, thank you very much, I never could think this way –  Dmitry Galchinsky Apr 15 '14 at 17:22

1 Answer 1

From what you've said in the comments, it appears that you simply need to call

clear functions

from the command line before recompiling the function to allow Matlab to overwrite the files. See this Matlab forum or the documentation for clear for more detail.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.