ボタンが押されたときに実行されるスクリプトがあり、whileループを開始します。私の停止ボタンが押されると、それはループ条件を真実にさせてループを停止させるはずです。私の停止ボタンはテスト中にループを止めていないようです。私がpushDisconnectボタンで割り当てた値がwhileループに更新されていないように見えますが、なぜこれが起こっているのかわかりません。ループが私の機能ボタンを認識しないwhileボタン
% --- Executes on button press in pushConnect.
function pushConnect_Callback(hObject, eventdata, handles)
% hObject handle to pushConnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','on')
set(handles.pushConnect,'Enable','off')
handles.myDevice.StartAcquisition;
sampleRate_BP = double(handles.myDevice.BioPotentialSignals.SamplesPerSecond);
axis_handles = zeros(1,handles.numEnabledBPChannels);
BioPotentialSignals = cell(1,handles.numEnabledBPChannels);
handles.CheckFinger = cell(1,5);
handles.stopNow = 0;
for ch = 1:handles.numEnabledBPChannels
axis_handles(ch) = subplot(length(axis_handles),1,ch,'Parent',handles.uipanelGraph);
if ch==1
title(char(handles.deviceName))
end
ylabel([char(handles.myDevice.BioPotentialSignals.Item(ch-1).Name) ' (V)']);
hold on
end
xlabel('Time (s)')
linkaxes(axis_handles,'x')
plotWindow = 5;
plotGain_BP = 1;
while handles.stopNow == 0
for ch = 1:handles.numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};handles.myDevice.BioPotentialSignals.Item(ch-1).GetScaledValueArray.double'];
if length(BioPotentialSignals{ch}) <= plotWindow*sampleRate_BP
cla(axis_handles(ch))
t = (0:(length(BioPotentialSignals{ch})-1))*(1/sampleRate_BP);
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch});
xlim([0 plotWindow])
else
if ch==1
t = ((length(BioPotentialSignals{ch})-(plotWindow*sampleRate_BP-1)):length(BioPotentialSignals{ch}))*(1/sampleRate_BP);
end
cla(axis_handles(ch))
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch}(end-plotWindow*sampleRate_BP+1:end));
xlim([t(end)-plotWindow t(end)])
end
end
% Update handles structure
guidata(hObject, handles);
pause(0.1)
disp(handles.stopNow)
end
% Stop signal
handles.myDevice.StopAcquisition;
% Disconnect from all sensors
handles.myDevice.Disconnect;
msgbox('Device requires cycling, in order to restablish connection. Closing program.')
% Close window
close all;
% --- Executes on button press in pushDisconnect.
function pushDisconnect_Callback(hObject, eventdata, handles)
% hObject handle to pushDisconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','off')
handles.stopNow = 1;
% Update handles structure
guidata(hObject, handles);
決勝ワーキングコード、誰もが興味を持っている場合:あなたは、時間のループで最新だったものは何でもしてGUIの状態を上書きしているので、
% --- Executes on button press in pushConnect.
function pushConnect_Callback(hObject, eventdata, handles)
% hObject handle to pushConnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','on')
set(handles.pushConnect,'Enable','off')
handles.myDevice.StartAcquisition;
sampleRate_BP = double(handles.myDevice.BioPotentialSignals.SamplesPerSecond);
axis_handles = zeros(1,handles.numEnabledBPChannels);
BioPotentialSignals = cell(1,handles.numEnabledBPChannels);
handles.CheckFinger = cell(1,5);
handles.stopNow = 0;
for ch = 1:handles.numEnabledBPChannels
axis_handles(ch) = subplot(length(axis_handles),1,ch,'Parent',handles.uipanelGraph);
if ch==1
title(char(handles.deviceName))
end
ylabel([char(handles.myDevice.BioPotentialSignals.Item(ch-1).Name) ' (V)']);
hold on
end
xlabel('Time (s)')
linkaxes(axis_handles,'x')
plotWindow = 5;
plotGain_BP = 1;
% Update handles structure
guidata(hObject, handles);
while handles.stopNow == 0
for ch = 1:handles.numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};handles.myDevice.BioPotentialSignals.Item(ch-1).GetScaledValueArray.double'];
if length(BioPotentialSignals{ch}) <= plotWindow*sampleRate_BP
cla(axis_handles(ch))
t = (0:(length(BioPotentialSignals{ch})-1))*(1/sampleRate_BP);
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch});
xlim([0 plotWindow])
else
if ch==1
t = ((length(BioPotentialSignals{ch})-(plotWindow*sampleRate_BP-1)):length(BioPotentialSignals{ch}))*(1/sampleRate_BP);
end
cla(axis_handles(ch))
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch}(end-plotWindow*sampleRate_BP+1:end));
xlim([t(end)-plotWindow t(end)])
end
end
handles = guidata(hObject);
drawnow
pause(0.1)
end
% Stop signal
handles.myDevice.StopAcquisition;
% Disconnect from all sensors
handles.myDevice.Disconnect;
msgbox('Device requires cycling, in order to restablish connection. Closing program.')
% Close window
close all;
% --- Executes on button press in pushDisconnect.
function pushDisconnect_Callback(hObject, eventdata, handles)
% hObject handle to pushDisconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','off')
handles.stopNow = 1;
% Update handles structure
guidata(hObject, handles);
両方とも試してみましたが、同じ問題です。 – IamTrent
@IlTrent:ちょうどguidata行に気づいた。あなたはGUI状態を上書きして、handles.stopNowが決して1つにならないようにします!回答が編集されました。 – Jonas
まだ同じ問題。 – IamTrent