Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Plotting individual cases on separate graphs

1 回表示 (過去 30 日間)
Ellen Walker
Ellen Walker 2018 年 9 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have multiple cases and for each case, multiple neurons. I can't figure out why my script loops through all cases and neurons, but rewrites the data so only the neurons for last case are plotted.
I appreciate any useful feedback!
Thank you!
Here is my code:
clear all; close all
file='/Users/ellenm.walker/Desktop/Lab matters/Maier Lab/MULTISENSORY/';
fileID=fopen('/Users/ellenm.walker/Desktop/Lab matters/Maier Lab/MULTISENSORY/PlasticityInfo.txt');
info=textscan(fileID,'%s%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f');
fclose(fileID);
for ff=1:length(info{1})
animal=strcat(info{1}{ff});
this_path=strcat('/Users/ellenm.walker/Desktop/Lab matters/Maier Lab/MULTISENSORY/',animal,'/');
session=strcat(info{2}{ff},'/');
probetype=info{8}(ff);
nchan=info{9}(ff);
fs=info{10}(ff);
sodr=info{16}(ff);
wodr=info{17}(ff);
isi_threshold=2;
plt=0;
tst=[0 11 13 6 2];
% tst=pump fluids
% 0=water; 11=MV; 13=2H; 6=saccharin; 2=sodium chloride
[spike_ts_merge,waves_merge,mua_ts,mua_waves]=Merge(this_path,session,probetype,nchan,fs,isi_threshold,plt);
[evt_ts,evt_id]=GetEventsComplete(this_path,session,tst,[],1,0);
pre=1000;
post=2500;
nunit=0;
neudata=[];
format shortG;
neudata*1e2;
for ii=1:length(spike_ts_merge)
if ~isempty(spike_ts_merge{ii})
units=unique(spike_ts_merge{ii}(:,2));
for jj=1:length(units)
nunit=nunit+1;
idx=find(spike_ts_merge{ii}(:,2)==units(jj));
spkbin=GetSpkbin(spike_ts_merge{ii}(idx,1),evt_ts,pre,post);
%get odor trial info
A=find((evt_id(:,1)==0) & ((evt_id(:,2)==wodr)));
B=find((evt_id(:,1)==0) & ((evt_id(:,2)==sodr)));
C=find((evt_id(:,2)==sodr));
D=find((evt_id(:,2)==wodr));
E=find((evt_id(:,1)==0) & ((evt_id(:,2)>0)));
odras=evt_id(E,2)
E(find(odras==sodr),2)=1;
E(find(odras==wodr),2)=0;
E(find(odras==sodr),3)=13;
E(find(odras==wodr),3)=11;
%plot responses
figure(nunit)
%plot neutral odor trials
M=mean(spkbin(A,:));
N=mean(spkbin(B,:));
sm=smooth(M,500,'lowess');
sm2=smooth(N,500,'lowess');
plot(sm,'g');
hold on
plot(sm2,'r');
legend('MV','2H');
title({animal;session});
hold off
H=findobj(gca,'Type','line');
X=get(H,'Xdata');
Y=get(H,'Ydata');
%Additions
L=length(M);
pre1=1:1000;
post1=1001:3500;
L2=length(N);
pre2=1:1000;
post2=1001:3500;
prewtr=mean(M(pre1));
postwtr=mean(M(post1));
presac=mean(N(pre2));
postsac=mean(N(post2));
neudata=[neudata;
1:length(info{1}),nunit,prewtr,postwtr,presac,postsac];
end
end
end
end
  2 件のコメント
Adam Danz
Adam Danz 2018 年 9 月 21 日
Just to make sure I understand, a figure is being created for every ' nunit' and both ' sm' and ' sm2' are plotted on the figure but on all of the figures it's the same set of data. Is that the problem?
Stephen23
Stephen23 2018 年 9 月 21 日
編集済み: Stephen23 2018 年 9 月 21 日
Ellen Walker's "Answer" moved here:
Yes, a new figure is being created for every 'unit' for each animal and both 'sm' and 'sm2' are plotted on each graph.
But the problem is, for some reason, the program creates all graphs for each animal, but the subsequent animal is overwritten so at the end of the program, the neurons for only the last animal appear.

回答 (1 件)

Adam Danz
Adam Danz 2018 年 9 月 21 日
編集済み: Adam Danz 2018 年 9 月 21 日
Some reverse engineering is needed to guess at what's being plotted but here's my guess at the problem.
Your ff-loop is the loop that iterates through the different animals. Within that loop you are resetting nunit=0. This variable is choosing the figure where the data will be plotted. So on the first iteration everything is fine. But starting on the 2nd animal, the figures begin to be overwritten because you're resetting nunit to 0 and then choosing figure 1 again.
Solution
Move nunit outside of the ff loop prior to the loop (but that might affect your variable neudata so a 2nd solution would be to create a different variable to control the figure number.
  1 件のコメント
Ellen Walker
Ellen Walker 2018 年 9 月 21 日
Thank you! I'll try this

この質問は閉じられています。

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by