-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotSpec.m
67 lines (57 loc) · 2.05 KB
/
plotSpec.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function plotSpec(rCond,roi,H)
if ~exist('roi','var'); roi = struct; end
if ~exist('H','var'); H = [] ; end
%% Assert
if iscell(roi)
roi = [roi{:}];
end
if iscell(H)
H = [H{:}];
end
roi = roi(:);
H = H(:);
% if all(size(roi) == flip(size(H))); roi = roi'; end
if length(roi) ~= length(H); dbstack; error('roi and H must have the same dimensions'); end
%% Setup figure
hF = figure('WindowStyle','docked');
if isempty(roi)
else
hA = cell(size(H));
for i = 1:length(H)
hA{i} = axes(hF,'Position',H(i).Position,'Box','on');
end
hA = [hA{:}]; hA = hA(:);
end
if isfield(roi(1),'vec') && isfield(roi(1).vec,'mt')
roiDataFlag = true;
else
roiDataFlag = false;
end
%% Plot spectra
if roiDataFlag
for i = 1:length(roi)
f = roi(i).vec.mt.psd.f;
spec = mean(roi(i).vec.mt.psd.vec,6);
plot(hA(i),squeeze(f),squeeze(spec),'k');
end
else
dbstack; error('double check roi data format');
dataMask = MRIread(rCond.volMt.runAv.psd.param.fMask); dataMask = dataMask.vol~=0;
f = rCond.volMt.runAv.psd.f;
spec = size(rCond.volMt.runAv.psd.PSD,1:8); spec(6) = length(roi); spec = zeros(spec);
for i = 1:length(roi)
vec2roi = roi{i}.mask(dataMask);
spec(:,:,:,:,:,i,:,:) = mean(rCond.volMt.runAv.psd.PSD(:,:,:,:,:,vec2roi,:,:),6);
end
end
% %% Plot PSD
% for i = 1:length(roi)
% plot(hA{i},squeeze(f),squeeze(spec(:,:,:,:,:,i,:,:)),'k');
% end
%% Adjust axes
for i = 1:length(H)
hA(i).XAxis.Color = H(i).XAxis.Color; hA(i).XAxis.LineWidth = H(i).XAxis.LineWidth;
hA(i).YAxis.Color = H(i).YAxis.Color; hA(i).YAxis.LineWidth = H(i).YAxis.LineWidth;
end
axis(hA,'tight'); yLim = get(hA,'YLim'); yLim = [min([yLim{:}]) max([yLim{:}])];
set(hA,'YLim',yLim,'YScale','log','XGrid','on','YGrid','on','XMinorGrid','on','YMinorGrid','on');