我现在在问题中得到了第二部分。 和以前一样,我有一个19 * 1000 * 134矩阵,我正在绘制,感谢Aero Engy在上一篇文章中的精彩回答。
我想在我的工作区中创建一个名为clean的向量,其长度为134。
默认情况下,clean(i)的值(i在1和134之间)将为1 - 但是,如果我按下UI界面上的按钮,则值必须为0。
我的代码吼叫,只是不要给我任何输出。按钮似乎工作,但当我关闭图形时,我没有得到矢量干净。
function cleanData(data);
% data = rand(19,1000,134);
global clean
clean = ones(1,size(data,3));
f = figure('Units','Normalized','Position',[0.25 0.25 0.5 0.5]);
a = axes('Units','Normalized','Position',[0.05 0.15, 0.75 0.75]);
s = uicontrol(f, 'Style','Slider', 'Units','Normalized','Position',[0.05 0.025, 0.75 0.05],...
'Min',1,'Max',size(data,3),'Value',1, 'Callback',{@sliderChange,a});
l = uicontrol(f, 'Style','listbox','Units','Normalized','Position',[0.85 0.15, 0.1, 0.75],...
'String',cellstr(num2str([1:size(data,1)]')),'Callback',{@changeChannel,a,s,data});
c = uicontrol(f, 'Style','pushbutton','Units','Normalized','String','Not clean',...
'Position',[0.85 0.025 0.1 0.05],'Callback',{@notClean,clean,s});
stepSize = 1/(s.Max - s.Min);
s.SliderStep = [stepSize 2*stepSize];
changeChannel(l,[],a,s,data)
function changeChannel(l,evtData,a,s,data)
cla(a);
chanNum = str2double(l.String{l.Value});
sR = 500; %500Hz
tempData = reshape(data(chanNum,:,:),[],size(data,3)); %Reshape each epoch into a column
tempTime = [0:1/sR:(size(data,2)-1)/sR]' + (0:1:size(data,3)-1)*2; %Build time array
plot(a,tempTime,tempData) %plot all the lines
s.Value = 1; %Rest Slider Position
function sliderChange(s,evtData,a)
viewI = round(s.Value);
disp(['Current Epoch: ' num2str(viewI)]) %console print
xlim(a,[(viewI-1)*2 viewI*2] + [-.1 .1])
function notClean(c,evtData,clean,s)
num = round(s.Value);
clean(num) = 0;
disp(['Epoch ' num2str(num) ' not clean']) %console print
我做错了什么?
奖金:如果
那就太好了感谢您的帮助,我是MATLAB的新手,即使我快速提高,我还远未完全理解这段代码。
答案 0 :(得分:1)
在notClean回调中,我将clean
称为全局。我也删除它作为输入...因为它是全局的,所以没有必要传递它。
每次按下按钮时,我都会添加代码以推进滑块1.
在关闭GUI以查看标记内容后的工作区中,您只需在命令行执行以下操作即可访问clean
数组。 (数字是我标记为不干净的随机事物。
我现在必须离开,所以我无法解决关于更换频道和跳过〜清洁元素的第二个问题......但它不应该很难。我会在几个小时后回到这里。
>> global clean
>> find(~clean)
ans =
3 4 11 19
修改后的代码: 编辑:在边缘添加了代码保护以跳过频道。
function cleanData(data)
% data = rand(19,1000,134);
global clean
clean = ones(1,size(data,3));
f = figure('Units','Normalized','Position',[0.25 0.25 0.5 0.5]);
a = axes('Units','Normalized','Position',[0.05 0.15, 0.75 0.75]);
s = uicontrol(f, 'Style','Slider', 'Units','Normalized','Position',[0.05 0.025, 0.75 0.05],...
'Min',1,'Max',size(data,3),'Value',1, 'Callback',{@sliderChange,a});
l = uicontrol(f, 'Style','listbox','Units','Normalized','Position',[0.85 0.15, 0.1, 0.75],...
'String',cellstr(num2str([1:size(data,1)]')),'Callback',{@changeChannel,a,s,data});
c = uicontrol(f, 'Style','pushbutton','Units','Normalized','String','Not clean',...
'Position',[0.85 0.025 0.1 0.05],'Callback',{@notClean,s,a});
stepSize = 1/(s.Max - s.Min);
s.SliderStep = [stepSize 2*stepSize];
changeChannel(l,[],a,s,data)
function changeChannel(l,evtData,a,s,data)
cla(a);
chanNum = str2double(l.String{l.Value});
sR = 500; %500Hz
tempData = reshape(data(chanNum,:,:),[],size(data,3)); %Reshape each epoch into a column
tempTime = [0:1/sR:(size(data,2)-1)/sR]' + (0:1:size(data,3)-1)*2; %Build time array
plot(a,tempTime,tempData) %plot all the lines
s.Value = 1; %Rest Slider Position
function sliderChange(s,evtData,a)
global clean
persistent prevI
if isempty(prevI)
prevI = 1;
end
viewI = round(s.Value);
sDir = sign(viewI - prevI); %-1 if going backwards +1 if going forward
prevI = viewI;
if clean(viewI) == 0
newPos = viewI + sDir;
if newPos < 1 || newPos > s.Max
return
end
s.Value = newPos;
sliderChange(s,[],a)
else
disp(['Current Epoch: ' num2str(viewI)]) %console print
xlim(a,[(viewI-1)*2 viewI*2] + [-.1 .1])
end
function notClean(c,evtData,s,a)
global clean %Call the global
num = round(s.Value);
clean(num) = 0;
disp(['Epoch ' num2str(num) ' not clean']) %console print
%Advance to the next slider position.
if num+1 < s.Max
s.Value = num+1;
sliderChange(s,[],a)
end
答案 1 :(得分:1)
修改后的代码也与第二部分一起使用:
public void cut(Time startTime, Time endTime) {
for (Iterator<Subtitle> iterator = subs.iterator(); iterator.hasNext();) {
Subtitle subtitle = iterator.next();
Time subtitleStartTime = subtitle.getStartTime();
Time subtitleEndTime = subtitle.getEndTime();
if (subtitleStartTime.getHH() >= startTime.getHH() &&
subtitleStartTime.getMM() >= startTime.getMM()
&& subtitleStartTime.getSS() >= startTime.getSS()
&& subtitleStartTime.getMS() >= startTime.getMS()
&& subtitleEndTime.getHH() <= endTime.getHH() &&
subtitleEndTime.getMM() <= endTime.getMM()
&& subtitleEndTime.getSS() <= endTime.getSS() &&
subtitleEndTime.getMS() <= endTime.getMS()) {
iterator.remove();
}
}
}