Problem with a yyaxis plot

everytime I execute the yyaxis function, following error message came up.
Error: File: union.m Line: 1 Column: 1
The input character is not valid in MATLAB statements or expressions.
Error in matlab.graphics.internal.YYAxisEventManager/addAxes
Error in matlab.graphics.internal.YYAxisEventManager
Error in matlab.graphics.internal.YYAxisEventManager.registerAxes
Error in yyaxis
The double yaxis figure is created, but the program stopped. If the figure is created and the yyaxis function is re-excuted, the error message does not show.
I am stuck here in desparation...please help

5 Comments

can you post your code?
function [timewindows] = tuningPlot(session, cellname, juiceAB)
if 0
clear all
session = 'B140620a'; cellname = '11';
end
disp([' ... plotting tuning results ',session,cellname])
readsession_autosort
[timewindows colrs] = get_timewindows_JC(session, cellname);
ntwins = length(timewindows);
filename = [dirroot, session, cellname, '_tuning']; eval(['load ',filename]) %generated by tuning.mat
verbose = 1;
if 0
clear all
tic
session = 'B140620a'; cellname = '11';
verbose = 1;
end
space = 'log';
dx = .005; % for Riemann's integral
epsilon = 0.0001; % for integration domain (how small the distr. before we ignore)
%load data
readsession_autosort
filename = [dirroot, session, cellname, '_data']; eval(['load ',filename])
filename = [dirroot, session, cellname, '_bhvParams']; eval(['load ',filename])
npairs = size(pairs,1);
%probability ratios
prob_ratios = zeros(npairs,1);
for ipair = 1:npairs
prob_ratios(ipair) = sessionParams.goods(pairlist(ipair,1)).probability / sessionParams.goods(pairlist(ipair,2)).probability;
end
%alloffers_num
alloffers_num = [];
for ipair = 1:npairs
table01 = table01_all.pooldir{ipair};
alloffers_num = [alloffers_num; table01(:,1:2)];
end
alloffers_num = unique(abs(alloffers_num),'rows');
eps = 0.001;
aux = alloffers_num + eps;
[~, jnd] = sort(aux(:,2)./aux(:,1));
alloffers_num = alloffers_num(jnd,:);
%
psyphycell = -ones(npairs, 3);
for ipair = 1:npairs
table01 = table01_all.pooldir{ipair};
%separate non-forced choice trials and forced choices
table1mod = table01(logical(table01(:,1) & table01(:,2)),:);
forcedAtab = table01(logical(table01(:,1) & ~table01(:,2)),:);
forcedBtab = table01(logical(~table01(:,1) & table01(:,2)),:);
nfA = size(forcedAtab,1);
nfB = size(forcedBtab,1);
%tuningy
xx = table1mod(:,2)./table1mod(:,1);
if isequal(space,'linear')
elseif isequal(space,'log')
xx = log(xx);
end
yy = table1mod(:,3);
g = fittype('normcdf(x,x0,w)','coeff',{'x0','w'});
[fittedmodel,goodness] = fit(xx, yy, g, ...
'startpoint',[0 1], 'lower',[-Inf 0], 'upper',[Inf Inf]);
coefit = [fittedmodel.x0, fittedmodel.w];
%find the end of integration domain, imposing value distr. < epsilon
leftlim = min(xx);
while normpdf(leftlim,coefit(1),coefit(2))>epsilon
leftlim = leftlim-dx;
end
rightlim = max(xx);
while normpdf(rightlim,coefit(1),coefit(2))>epsilon
rightlim = rightlim+dx;
end
%compute relvalue (NB: in log space, it is not just the center of the value distrib.)
if isequal(space,'linear')
relvalue = fittedmodel.x0;
width = fittedmodel.w;
elseif isequal(space,'log')
relvalue = exp(fittedmodel.x0);
width = exp(fittedmodel.w);
end
Rsq = goodness.adjrsquare;
%extract tuning results
tuningWindowInd = struct2cell(tuning.AB.neuract.byoffertype);
tuningWindow = tuningWindowInd{:};
%tuningX = find(tuningWindow(:,3) == 1 & tuningWindow(:,6)>10);
tuningX = tuningWindow(:,3);
% tuningY = find(tuningWindow(:,3) == -1 & tuningWindow(:,6)>10);
tuningY = tuningWindow(:,4);
tuner(1,:) = tuningX;
tuner(2,:) = tuningY;
%take care of outliers
if (isequal('space','log') && confinterval(2)>5) || (isequal('space','linear') && confinterval(2)>100)
confinterval(2) = NaN;
disp(['manually corrected confinterval']);
end
psyphycell(ipair,:) = [fittedmodel.x0, fittedmodel.w, Rsq];
%this should be made part of the function plot_sigmoid
if verbose
colrs = [0 0 0; ones(npairs,1)*[0 0 1]];
%initialize figures
%if ipair==1
% hf = figure; set(gcf, 'position',[650 620 425 350], 'PaperPositionMode','auto')
% end
orient landscape
set(gcf,'position',[200 200 960 720]);
hold on
warning off;
axis square;
yyaxis left;
%% %plot choice pattern + forced choices
plot(xx,yy,'o','color',colrs(1,:),'markersize',8,'markerfacecolor',colrs(1,:))
hold on
xx_forcedA = min(xx)-log(2)*[1:nfA]; xx_forcedA = sort(xx_forcedA)';
xx_forcedB = max(xx)+log(2)*[1:nfB]; xx_forcedB = sort(xx_forcedB)';
plot(xx_forcedA,zeros(1,nfA),'o','color',colrs(1,:),'markersize',8,'markerfacecolor',colrs(1,:))
plot(xx_forcedB, ones(1,nfB),'o','color',colrs(1,:),'markersize',8,'markerfacecolor',colrs(1,:))
ylabel('Percent choosing A')
set(gca,'ytick',[0:.25:1],'yticklabel',[0:25:100])
%
yyaxis right
%plot tuning curve
plot(xx(1:length(tuner(juiceAB,2:(end-1)))),tuner(juiceAB,2:end-1),'bo-')
hold on
%plot(xx((end+1-length(tuningY(1:end-1))):end),tuningY(1:end-1),'bd-')
plot(xx_forcedA,tuner(juiceAB,1),'bo')
plot(xx_forcedB,tuner(juiceAB,end),'bo')
%cosmetics
set(gca,'xlim',[min(xx)-1.5*log(2) max(xx)+1.5*log(2)])
set(gca,'ylim',[min(tuner(juiceAB,:))-1.5*log(2) max(tuner(juiceAB,:))+1.5*log(2)])
ylabel('Firing Rate');
[~,ind,~] = unique(xx); %remove doubles in xx
xxx = xx(ind);
%
xlab = []; %xlabels
for ifA = 1:nfA
xlab{ifA} = [num2str(forcedAtab(nfA-ifA+1,2)),':',num2str(forcedAtab(nfA-ifA+1,1))];
end
for i = 1:size(xxx,1)
xlab{nfA+i} = [num2str(table1mod(ind(i),2)),':',num2str(table1mod(ind(i),1))];
end
for ifB = 1:nfB
xlab{nfA+i+ifB} = [num2str(forcedBtab(nfB-ifB+1,2)),':',num2str(forcedBtab(nfB-ifB+1,1))];
end
%
%add forced choices
xxx = [xx_forcedA;xxx;xx_forcedB];
set(gca,'xtick',xxx,'xticklabel',xlab)
%xticklabel_rotate([],90,[]);
% %
% text(min(x)-.5,.925,['\mu = ', sprintf('%1.3g',relvalue)],'fontsize',9)
% text(min(x)-.5,.855,['\sigma = ',sprintf('%1.3g',width)], 'fontsize',9)
%
%mark cellname
if ipair == npairs
axes('position',[.1 .925 .5 .015])
text(0,3,[' session: ',session,' sigmoid fit (',space,' space)'], ...
'fontname','timesnewroman','fontsize', 8)
axis off
set(gcf,'PaperPositionMode','auto')
end
if (ipair==3)
set(gcf,'position',[200 600 1200 350]);
end
end %if verbose
end
It is not a good idea to call clear all in your functions.
Clear all will clear all the variables, including th variable juiceAB which you are using further down in your plotting.
This maybe the source of the error.
I only called clear all when verbose = 0, but as you see the "clear all" code is never executed.
However I still delete these and the error persists....
Thank you though
Can you show the output of following statement after running in command window?
which union
It seems that the MATLAB files somehow got messed up. You may need to uninstall and reinstall MATLAB completely. Can you tell which MATLAB release are you using?

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Tags

Asked:

on 15 Apr 2020

Edited:

on 21 May 2020

Community Treasure Hunt

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

Start Hunting!