Ошибка определения типа для ввода 'concealc: Calc '. Невозможно объединить кодер.StructTypes с различными наборами полей

Когда я пытаюсь преобразовать программу Matlab как группу, которая включает несколько функций, в программу на C++ с помощью приложения для кодировщика Matlab, я получаю сообщение об ошибке:  введите здесь описание изображения. И переменная calc является структурой в Matlab. Однако, если я попробую саму функцию concealc, проблем не возникнет. В чем проблема?

Вот код функции concealc:

function [calc] = conscalc(rho, gv, calc)
tp = 1 + rho;
sqrt2 = sqrt(2);  
consadj = 2 ^ (0.5 * (1 - calc.alpha));

% initialization;
cv = zeros(gv.nacatlim, 1); % consumption equivalents of future expected marginal utility;
yac = zeros(gv.nacatlim, 1); % income (y) - end of period asset (a) - optimal consumption given end of period asse (c);
margu = zeros(gv.nvcatlim, gv.nacatlim); % marginal utility next period by next period survival status (1 - 3) and initial asset (1 - gv.nacatlim);
cons = zeros(gv.T - gv.beginage + 1, gv.nvcatlim, gv.nacatlim); % optimal consumption at the current period by age (25 - 99), survival status (1 - 3) and initial asset (1 - gv.nacatlim);

% simplified backward induction;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calculate optimal consumption and marginal utility for the terminal age %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the optimal decision is to consume everything at the terminal age;
for vcat = 1: 3; % survival status;
    for acat = 1 : gv.nacatlim; % asset;

        y = calc.acats(acat, 1) + calc.income(vcat, gv.T - gv.beginage + 1); % total resources in the last period given initial asset and income;

        mu = y ^ (calc.alpha - 1); % marginal utility given next period survival status and initial asset; 

        if vcat == 1; % married couple adjustment;
            mu = consadj * mu;
        end;

         % save to marginal utility next period (when calculating backward to age - 1) for later calculations;
        margu(vcat, acat) = mu;

    end;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% calculate optimal consumption and marginal utility for ages gv.t to gv.T - 1 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for age = gv.T - 1 : -1 : gv.beginage; % age;
    for vcat = 1 : 3; % survival status;

        y = calc.income(vcat, age - gv.beginage + 1); % income given survival status and age;

        % calculate expected marginal utility next period given current period end of period asset;
        for acat = 1 : gv.nacatlim; % asset;

            mu = 0; % expected marginal utility next period given current period survival status and end of period asset;

            for rcat = 1 : gv.nrcatlim; % asset return shock;

                mur = 0; % marginal utility next period given current period survival status, end of period asset and asset return shock;

                % (end of period asset + saving) * asset return shock is asset next period;
                % interpolation;
                % find corresponding asset grid point of the next period initial asset given current period end of period asset and asset return shock;
                acatf = floor(calc.rtransa(acat, rcat));

                if acatf >= gv.nacatlim;
                    acatf = gv.nacatlim - 1;
                end;
                fa = calc.rtransa(acat, rcat) - acatf;

                for vcatt = 1 : 3; % survival status next period;

                    if vcatt == 1 || (vcat == 1 && age >= gv.surviveage); % the codes are not right. if vcat == 2/3, the program uses margu(1, acatf); should use margu(2/3, acatf); ??? 


                        mu0 = margu(vcatt, acatf);

                        mu1 = margu(vcatt, acatf + 1);

                        if mu0 <= 0 || mu1 <= 0;
                            fprintf('Interpolaton Error: Bad mu in rho section: %2d %2d %14.6e %14.6e %2d %2d %2d', ...
                                calc.obs, age, mu0, mu1, vcat, acat, rcat);
                            return;
                        end;

                        if fa <= 1;
                            murv = (1 - fa) * mu0 + fa * mu1;
                        else
                            if mu0 > mu1;
                                dmu = mu0 - mu1;
                                mufact = dmu / mu0;
                                murv = mu1 / (1 + (fa - 1) * mufact);
                            else
                                murv = mu1;
                            end;
                        end;

                        if vcat == 1 && age >= gv.surviveage; % both spouses alive;
                            mur = mur + calc.transrate(vcatt, age - gv.beginage + 1) * murv;
                        else
                            mur = mur + murv;
                        end;

                    end;

                end;

                mu = mu + calc.rprob(rcat, 1) * mur;

            end;

            % marginal utility this period should equal to the discounted expected marginal utility next period;
            % convert optimal discounted expected marginal utility back to consumption level;
            if vcat == 1; % both spouses alive;
                cv(acat, 1) = sqrt2 * (mu / tp) ^ (1 / (calc.alpha - 1));
            elseif vcat == 2 || vcat == 3; % only one spouse alive;
                cv(acat, 1) = (mu * calc.srate(vcat - 1, age - gv.beginage + 1) / tp) ^ (1 / (calc.alpha - 1));
            end;

            yac(acat, 1) = y - calc.acats(acat, 1) - cv(acat, 1); % income - end of period asset - consumption;

        end;

        % find optimal consumption at the current period given initial asset;
        k = 1; % initialize asset grid point;
        for acat = 1 : gv.nacatlim; % asset;

            nassets = - calc.acats(acat, 1); % - initial asset level at the current period;

            % find how much asset left after consumption;
            % - asset(t) = income - end of period asset(t) - optimal consumption(t) given end of period asset(t); 
            % interpolation;
            if yac(k, 1) < nassets;

                k = k - 1;
                while k >= 1 && yac(k, 1) < nassets;
                    k = k - 1;
                end;

                if k < 1; % optimal to leave no assets to next period;
                    f = 0;
                    k = 1;
                elseif k >= 1;
                    f = (yac(k, 1) - nassets) / (yac(k, 1) - yac(k + 1, 1));
                end;

            elseif yac(k, 1) >= nassets;

                while k < gv.nacatlim && yac(k + 1, 1) >= nassets;
                    k = k + 1;
                end;

                if k > gv.nacatlim - 1; % requires extrapolation;
                    k = gv.nacatlim - 1;
                    if cv(k + 1, 1) > cv(k, 1);
                        f = (yac(k, 1) - nassets) / (yac(k, 1) - yac(k + 1, 1));
                    else
                        f = 1 + (yac(k + 1, 1) - nassets) / (calc.acats(k + 1, 1) - calc.acats(k, 1));
                    end;
                elseif k <= gv.nacatlim - 1;
                    f = (yac(k, 1) - nassets) / (yac(k, 1) - yac(k + 1, 1));
                end;

            end;

            c = y + calc.acats(acat, 1) - ((1 - f) * calc.acats(k, 1) + f * calc.acats(k + 1, 1)); % optimal consumption at the current period;

            % calculate marginal utility at the current period given optimal consumption;
            if vcat == 1; % married couple adjustment;
                mu = consadj * c ^ (calc.alpha - 1);
            elseif vcat == 2 || vcat == 3; 
                mu = c ^ (calc.alpha - 1);
            end;

            % save optimal consumption to corresponding optimal consumption matrix for later calculations; 
            cons(age - gv.beginage + 1, vcat, acat) = c; % optimal consumption at the current period;
            margu(vcat, acat) = mu; % marginal utility next period (when calculating backward at age - 1), given survival status and initial asset;
        end;

    end;
end;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% assign the values to structure variable calc for future calculations %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
calc.cons = cons;



end

1 ответ

Ошибка предполагает, что во время автоматического определения типа ввода ваша функция вызывается со структурами, которые имеют разные наборы полей.

Для отладки поместите точку останова в функцию точки входа в MATLAB и запустите сценарий тестирования определения ввода. Обратите внимание на передаваемые структуры, чтобы увидеть, где происходит несоответствие.

Другие вопросы по тегам