Undefined function 'plus' for input arguments of type 'matlab.ui.Figure'.

I get this error message when I run a script that was given to me on my data and may well have been written in an earlier version - I am working 2014b.
Any ideas? This is the full error message, but I haven't copied the script in as it's really quite long.
Undefined function 'plus' for input arguments of type 'matlab.ui.Figure'.
Error in PRL_analyseData>getNewFig (line 538) hfig = varargin{1}+1;
Error in PRL_analyseData (line 160) hfig = getNewFig(hfig,cmap);

1 个评论

You probably need to rework the script to use an array of figure objects rather than doing maths on the old handles to refer to presumably the next figure.

请先登录,再进行评论。

 采纳的回答

The reason it does not work in 2014b is because figures handles are no longer numbers. Thus you can't add 1 to them anymore.
Without seeing anymore of the code, it's difficult to give you any advice on how to solve this.

6 个评论

I haven't played with 2014b yet but it looks like a lot of my plotting functions are going to break. Oh well, Matlab graphics have not been particularly pretty so this is an ---annoying--- step in the right direction.
Shot in the dark:
hfig = varargin{1}.Number + 1;
Thank you for your comments - appreciate the help. The above didn't work sadly.
Guillaume - I'm afraid I'm too much of a matlab novice to really know which part(s) of the code are useful to copy over.
Is this helpful?
function hfig = getNewFig(varargin);
hfig = varargin{1}+1;
hfig = figure; hold on; box off
if numel(varargin)==2
set(hfig,'DefaultAxesColorOrder',varargin{2},'position',[10 60 500 500],...
'paperunits','centimeters','paperposition',[0 0 6 6],'Color','w');
else
set(hfig,'position',[10 60 500 500],...
'paperunits','centimeters','paperposition',[0 0 6 6],'Color','w');
end
end
If that is indeed the code, then you can just delete the line
hfig = varargin{1}+1;
as it doesn't do anything. hfig is just overwritten in the next line.
Actually, you could rewrite the function as:
function hfig = getNewFig(~, colororder)
hfig = figure; hold on; box off
set(hfig,'position',[10 60 500 500],...
'paperunits','centimeters','paperposition',[0 0 6 6],'Color','w');
if nargin == 2
set(hfig,'DefaultAxesColorOrder',colororder);
end
end
It would do exactly the same, and would be cleaner. Even cleaner would be to get rid of the first argument which is not used, but that would also require you to modify all the calls to the function.
While any of the above should get rid of the error you've reported, it's possible you'll run into the same problem further along the code. You will have to post that section of code as well, if you can't figure out how to solve it.
Follow up to the misplaced comment/answer:
Replace the first line of
for t = 1:hfig
print(t,'-depsc','-tiff','-r300',sprintf('Figure%d',t));
end
by
for t = 1:hfig.Number
If you're happy with the solution provided, you should accept it.

请先登录,再进行评论。

更多回答(2 个)

Many thanks, that has definitely helped. However I now have a different error message:
Undefined function 'vline' for input arguments of type 'double'.
Error in PRL_analyseData (line 266)
vline(40.5,'k:');
This is the section of the code it relates to. Is it to do with 2014b changes again?
% average and smoothed average probability of chosing correctly on each
% trial
choiceBinary = choice;
choiceBinary(choice==2)=0;
plotdata{1} = choiceBinary;
plotdata{2}= mySmooth(choiceBinary,span,2);
for n = 2 % can also plot the raw data, then n=1
hfig = getNewFig(hfig,cmap);
mu = []; sem = [];
for t = cond
mu(:,t) = mean(plotdata{n}(groupMember==t,:));
switch n
case 1
plot(mu(:,t),'linewidth',2,'color',cmap(t,:))
case 2
sem(:,t) = std(plotdata{n}(groupMember==t,:),[],1)/sqrt(nsgroup(t)); end
end
if n==2
b = nan(nt,1,max(cond));
b(:,1,:) = sem;
x = repmat(1:nt,max(cond),1)';
boundedline(x,mu,b,'alpha','cmap',cmap)
end
legend(groupLabel,'location','Best')
vline(40.5,'k:');
xlabel('trial');
ylabel('p(stimulus1)')
ylim([0 1])
end

4 个评论

Please, reply in comments rather than starting a new answer.
This has nothing to do with 2014b. vline is not a function that ships with matlab. Most likely it came from the file exchange
This I've actually managed to resolve with further investigation. Thanks
My apologies. Yes, I worked out that vline came from the file exchange. Thanks. I now have an issue with:
No method 'colon' with matching signature found.
Error in PRL_analyseData (line 303)
for t = 1:hfig
This relates to this section of the script:
hfig = getNewFig(hfig,cmap);
mu = []; sem = [];
for t = cond
mu(1,t) = mean(WS(groupMember==t));
mu(2,t) = mean(LS(groupMember==t));
sem(1,t) = mean(WS(groupMember==t))/sqrt(nsgroup(t));
sem(2,t) = mean(LS(groupMember==t))/sqrt(nsgroup(t));
end
barweb(mu,sem,groupLabel,{'WStay','LShift'},'Best',0.8,cmap);
set(gca,'xtick',1:2);
for t = 1:hfig
print(t,'-depsc','-tiff','-r300',sprintf('Figure%d',t));
end
end
I am reading about signatures in order to try and resolve this, but would appreciate any help
Please, find the reply as a comment to my answer rather than here.

请先登录,再进行评论。

An updated answer to this is to overload the 'plus' function. It seems that matlab calls the builtin for inline operators by default, even if the overload doesn't pay any attention to the rules for overloading a function. I have no idea why this is though, as overloading other critical functions like sprintf seems to cause a world of pain.
Regardless of the reason, this oddity means the following function can be placed anywhere in your path, and it will only be called if the regular plus function can't handle the inputs, so it doesn't impact normal behavior or performance.
function out = plus(A,B)
try
out = double(A) + double(B)
catch
%Fail with the built-in
builtin('plus',A,B)
end

类别

帮助中心File Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by