Problem in nested function

13 vues (au cours des 30 derniers jours)
Mahesh
Mahesh le 30 Mai 2015
Commenté : Mahesh le 30 Mai 2015
While I trying to make a routine with nested function as shown below
function [ resobj ] = plot4Paper(data_choice, prgms, fitcases, ~)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
q = [-5 5 0.1];
ndays = 5;
nprgms = numel(prgms);
npset = numel(fitcases);
if npset == nprgms, disp('No matches found'); end
ibest = zeros(npset,0);
for i = 1:nprgms
prgm = prgms(i);
nparam = FMvariants_cont( prgm );
icase = fitcases(i);
[dirGraph, RName, Filein, ~, FileOut] = drawer(data_choice, prgm);
data = getdata(Filein); data = data(:);
ndata = numel(data);
[p, itn] = paramget(FileOut, nparam, 4, icase);
ibest(i,1) = itn;
resobj.data = data;
dataR = load(['Data\' RName '.rdata']);
resobj.dataR = dataR;
resobj.nparam{i} = nparam;
resobj.prggm{i} = prgm;
resobj.pbest{i} = p;
resobj.bestcase{i} = ibest(i);
dy = getprojection(p, prgm, ndata);
dy = stat_moving(dy, ndays);
resobj.dy{i} = dy;
resobj.stats{i} = statsummary(data, dataR, dy, q, '');
end
dys = zeros(ndata, nprgms);
dys(:,1) = resobj.data;
for i = 1:nprgms
dys(:,i+1) = resobj.dy{i};
end
resobj.dys = dys;
maxpk = max(max(resobj.dys));
resobj.normdata = dys/maxpk;
for i = 1:nprgms
if i == 1
prt = 'Y';
else
prt = '';
end
f = plotdatady(dys(:,1), dys(:,i+1), prt);
end
function dy = getprojection(p, prgm, ndata)
p; ndata;
expr = ['dy = fm_model_' int2str(prgm) '(p, ndata);'];
eval(expr);
end
function f = plotdatady(X, Y, A)
ndata = numel(X);
f = figure();
dyplot= subplot(1,3,[1 2]);
hold on
plot(1:ndata,X,'Color', zeros(1,3), 'LineWidth',1.0);
plot(1:ndata,Y,'Color',gr*ones(1,3));
hold off
set(dyplot,'FontSize',28)
set(gca,'Xtick',[1 ndata]);
set(gca,'Xlim',[1 ndata]);
set(gca,'TickLength',[0 0]);
set(gca,'Ytick',[0 1]);
set(gca,'Ylim',[-0.05 1]);
t1 = title(Tlabel);
set(t1, 'FontSize',32);
box on
cumplot = subplot(1, 3, 3);
cumR=cumsum(X);
cumP=cumsum(Y);
plot(1:ndata,cumR,'Color', zeros(1,3), 'LineWidth',1.0);hold
plot(1:ndata,cumP,'Color',gr1*ones(1,3));hold; hold on
Lc = min(min(cumR), min(cumP));
Uc = max(max(cumR), max(cumP));
fitline = linspace(Lc, Uc, ndata); fitline=fitline(:);
plot(fitline, '-k'); hold
set(cumplot,'FontSize',28)
set(gca,'Xtick',[0 ndata]);
set(gca,'Xlim',[0 ndata]);
set(gca,'TickLength',[0 0]);
set(gca,'Ytick',[0 1]);
set(gca,'Ylim',[-0.05 1]);
if A == 'Y'
t0 = title('Accumulated');
set(t0, 'FontSize',32);
end
box on
end
I got an error message like *"Error: File: plot4Paper.m Line: 94 Column: 4 The function "plotdatady" was closed with an 'end', but at least one other function definition was not. To avoid confusion when using nested functions, it is illegal to use both conventions in the same file." Could you please help me to solve this problem Thanks in advance

Réponse acceptée

Nobel Mondal
Nobel Mondal le 30 Mai 2015
Modifié(e) : Nobel Mondal le 30 Mai 2015
Looks like, you haven't closed all of your function definition with an 'end'.
function [ resobj ] = plot4Paper(data_choice, prgms, fitcases, ~)
%%%Do stuff
end
I didn't try to run your code as I don't have any sample of the input arguments. It should be placed just before you define
function dy = getprojection(p, prgm, ndata)
  1 commentaire
Mahesh
Mahesh le 30 Mai 2015
Thanks to all. I got the mistake figured out.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 30 Mai 2015
The "end" that you have right before
function dy = getprojection(p, prgm, ndata)
is matching the "for".
You need to add another "end" before that "function" statement.

Catégories

En savoir plus sur Fluid Dynamics dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by