How to add two other curves to the final plot ?

조회 수: 4 (최근 30일)
Rudy Lussiez
Rudy Lussiez 2018년 4월 1일
답변: William Smith 2018년 4월 3일
Hello ! So I actually have two questions. The first one obviously is that I want to run the following script for three sets of Y values, that share the same X values, and I would like the scriopt to plot the 3 curves into one single plot. I only have basic knowledge of Matlab and don't want to mess up this script. Second, I would like the output text to be written in a column instead of a line, and return the same parameters for the 2 supplementary curves that I want to add. Does anyone have an idea to accomplish all of this ? Thanks !
function fitOrientationAndPlot(xdata, ydata, vecError, clrFig,numRep) %%% results4save = [drCirVar DI theta_pref halfWidth(1) rep_pref theta_null halfWidth(2) rep_null theta_ortplus rep_ortplus theta_ortmin rep_ortmin baseline];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%References variables %%%%
%%%%as Mazurek, Kager %%%%
%%%%and van Hooser, %%%%
%%%%Front. Neur. Cir. %%%%
%%%%2014 %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x(1) tunning width peak
x(2) AngPref
x(3) Max Firing Rate
x(4) Baseline
persistent baseline rtMax_pref Ang_pref
[rtMax_pref, posAng_pref] = max(ydata);
Ang_pref = xdata(posAng_pref);
xCircData = xdata;
yCircData = ydata;
vecCircError = vecError;
alpha = diff(xdata(1:2));
%%%plot properties
xlimPlot = [0 180];
xAxis = [0:45:180];
llAxis = length(xdata)-1;
[c index] = min(abs(xCircData));
xCircAxis = xCircData(index:index+llAxis);
yCircAxis = yCircData(index:index+llAxis);
eCircAxis = vecCircError(index:index+llAxis);
baseline = min(ydata);
drCirVar = 1 - abs(sum(ydata .* exp(2* i * deg2rad(xdata))) / sum(ydata));
fun = @(x,xdata) (x(4) + x(3)*exp(-(((xdata-x(2)).^2)/(2*x(1)*x(1))))); %%%%Gaussian
lb = [alpha/2 Ang_pref-alpha/5 0 0];
ub = [1000 Ang_pref+alpha/5 rtMax_pref*3 rtMax_pref];
options = optimset('Display','off'); %%%Options fit
resnorm = 100000;
num = 0;
x = zeros(1,4);
while(num < numRep)
x0(1) = (ub(1)-lb(1)).*rand + lb(1);
x0(2) = (ub(2)-lb(2)).*rand + lb(2);
x0(3) = (ub(3)-lb(3)).*rand + lb(3);
x0(4) = (ub(4)-lb(4)).*rand + lb(4);
[newX,newResnorm,residual,exitflag,output]=lsqcurvefit(fun,x0,xCircData,yCircData,lb,ub,options);
if(resnorm > newResnorm)
x = newX;
resnorm = newResnorm;
end
num = num + 1;
end
outputResults = x;
bandWidth = outputResults(1:2);
%%%%Dir_pref from fit %%%%%%
times = linspace(xCircData(1),xCircData(end), 500);
y = fun(x,times);
x = times;
%%%%%%Here R2 %%%%%%%%%%%
[rep_pref, posAux] = max(y);
theta_pref = x(posAux);
if(theta_pref >= 90)
theta_pref = mod(theta_pref,180);
theta_null = theta_pref - 90;
else
theta_null = theta_pref + 90;
end
[~, index] = min(abs(x-theta_null));
rtNull = y(index); %%%%%%%%%%%%rate Nulll if you want to modify
halfWidth = sqrt(log(4)) * bandWidth;
baseline = outputResults(4);
OI = 1 - (rtNull)/rtMax_pref;
outputWrite = ['cv=', num2str(drCirVar), ' OSI=', num2str(OI), ' theta_p=', num2str(theta_pref), ' BW_p=', num2str(halfWidth(1)),' R_p=', num2str(rep_pref), ' baseline=', num2str(baseline), ' theta_null=', num2str(theta_null),' RateNull=', num2str(rtNull)];
disp(outputWrite)
%
%%%%Plot results %%%%
h = errorbar(xCircAxis, yCircAxis, eCircAxis, ['o', clrFig], 'MarkerFaceColor', clrFig);
hold on
plot(times,y ,['-', clrFig]);
xlim(xlimPlot);
ylabel('Firing Rate (spikes/sec)', 'FontSize',12);
xlabel('Direction (deg)', 'FontSize', 12);
axisPSTHnum = xAxis';
axisPSTHstr = num2str(xAxis.', '%.f');
set(gca,'XTickMode','manual');
set(gca,'XTick', axisPSTHnum);
set(gca,'XtickLabels',axisPSTHstr);
box off
set(gca,'XColor','k','YColor','k','TickDir','out', 'LineWidth', 2,'FontSize',12);

답변 (1개)

William Smith
William Smith 2018년 4월 3일
Answer 1 :
hold('on');
Answer 2 : ???

Community Treasure Hunt

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

Start Hunting!

Translated by