デバイスからの読みを自分のGUIに表示する機能があります。現時点では、最後のサブプロットだけがGUI図内に表示されるという問題があります.GUIでは、3つの他のプロットが存在するはずの空白(軸とグラフデータなし)が表示されます。第4サブプロットはすべてのデータを完全に示しています。私は、デバイスからのデータを使用せずにこの関数をテストしました。そして、関数内からFigureを(GUIではなく)起動すると、すべてのサブプロットが表示されます。ハンドルを介してGUIにアクセスすると、最後のサブプロットだけが表示されます
axes1はGUIのmy axesタグです。
function BioRadioData = BioRadio_Stream2(myDevice , duration , BioRadio_Name , axes1)
numEnabledBPChannels = double(myDevice.BioPotentialSignals.Count);
if numEnabledBPChannels == 0
myDevice.Disconnect;
BioRadioData = [];
errordlg('No BioPotential Channels Programmed. Return to BioCapture to Configure.')
return
end
sampleRate_BP = double(myDevice.BioPotentialSignals.SamplesPerSecond);
sampleRate_Pod = 250;
axis_handles = zeros(1,numEnabledBPChannels);
disp(axis_handles)
disp(length(axis_handles))
for ch = 1:numEnabledBPChannels
axis_handles(ch) = subplot(length(axis_handles),1,ch,axes1);
disp(ch)
if ch==1
title(char(BioRadio_Name))
end
ylabel([char(myDevice.BioPotentialSignals.Item(ch-1).Name) ' (V)']);
hold(axes1,'on')
end
xlabel('Time (s)')
linkaxes(axis_handles,'x')
BioPotentialSignals = cell(1,numEnabledBPChannels);
myDevice.StartAcquisition;
plotWindow = 5;
plotGain_BP = 1;
elapsedTime = 0;
tic;
while elapsedTime < duration
pause(0.08)
for ch = 1:numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};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
elapsedTime = elapsedTime + toc;
tic;
end
myDevice.StopAcquisition;
BioRadioData = cell(1,1);
BioRadioData{1} = BioPotentialSignals;
end
このコードセグメントは機能しますが、作成されたGUIには別の数字が生成されます。上記のコードはGUI内の4番目のプロットのみを生成しますが、
function BioRadioData = BioRadio_Stream2(myDevice , duration , BioRadio_Name)
numEnabledBPChannels = double(myDevice.BioPotentialSignals.Count);
if numEnabledBPChannels == 0
myDevice.Disconnect;
BioRadioData = [];
errordlg('No BioPotential Channels Programmed. Return to BioCapture to Configure.')
return
end
sampleRate_BP = double(myDevice.BioPotentialSignals.SamplesPerSecond);
sampleRate_Pod = 250;
axis_handles = zeros(1,numEnabledBPChannels);
disp(axis_handles)
disp(length(axis_handles))
figure
for ch = 1:numEnabledBPChannels
%axis_handles(ch) = subplot(length(axis_handles),1,ch,axes1);
axis_handles(ch) = subplot(length(axis_handles),1,ch);
disp(ch)
if ch==1
title(char(BioRadio_Name))
end
ylabel([char(myDevice.BioPotentialSignals.Item(ch-1).Name) ' (V)']);
%hold(axes1,'on')
hold on
end
disp(axis_handles)
disp(length(axis_handles))
disp(ch)
xlabel('Time (s)')
linkaxes(axis_handles,'x')
BioPotentialSignals = cell(1,numEnabledBPChannels);
myDevice.StartAcquisition;
plotWindow = 5;
plotGain_BP = 1;
elapsedTime = 0;
tic;
while elapsedTime < duration
pause(0.08)
for ch = 1:numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};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});
hold(axis_handles(ch),'on')
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));
hold(axis_handles(ch),'on')
xlim([t(end)-plotWindow t(end)])
end
end
elapsedTime = elapsedTime + toc;
tic;
end
myDevice.StopAcquisition;
BioRadioData = cell(1,1);
BioRadioData{1} = BioPotentialSignals;
end
テストデータ
function varargout = ProjectGUI5test(varargin)
% PROJECTGUI5TEST MATLAB code for ProjectGUI5test.fig
% PROJECTGUI5TEST, by itself, creates a new PROJECTGUI5TEST or raises the existing
% singleton*.
%
% H = PROJECTGUI5TEST returns the handle to a new PROJECTGUI5TEST or the handle to
% the existing singleton*.
%
% PROJECTGUI5TEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PROJECTGUI5TEST.M with the given input arguments.
%
% PROJECTGUI5TEST('Property','Value',...) creates a new PROJECTGUI5TEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ProjectGUI5test_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ProjectGUI5test_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ProjectGUI5test
% Last Modified by GUIDE v2.5 01-Apr-2016 16:25:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ProjectGUI5test_OpeningFcn, ...
'gui_OutputFcn', @ProjectGUI5test_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ProjectGUI5test is made visible.
function ProjectGUI5test_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ProjectGUI5test (see VARARGIN)
% Choose default command line output for ProjectGUI5test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ProjectGUI5test wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ProjectGUI5test_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in connectbutton.
function connectbutton_Callback(hObject, eventdata, handles)
% hObject handle to connectbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
%loads handles into the function
BioRadioData = BioRadio_Stream3(30 , handles.axes1);
% --- Executes on button press in disconnectbutton.
function disconnectbutton_Callback(hObject, eventdata, handles)
% hObject handle to disconnectbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
function BioRadioData = BioRadio_Stream3(duration , axes1)
% function BioRadioData = BioRadio_Stream(myDevice , duration , BioRadio_Name)
% BioRadio_Stream streams data from the BioRadio and imports it into MATLAB.
%
% INPUTS:
% - myDevice is a handle to a BioRadio device object
% - duration is the data collection interval in seconds
% - BioRadio_name is string containing the BioRadio name
numEnabledBPChannels = 4;
sampleRate_BP = 1000;
axis_handles = zeros(1,numEnabledBPChannels);
for ch = 1:numEnabledBPChannels
axis_handles(ch) = subplot(length(axis_handles),1,ch,axes1);
disp(ch)
if ch==1
title('Title')
end
ylabel(' (V)');
hold(axes1,'on')
end
xlabel('Time (s)')
linkaxes(axis_handles,'x')
BioPotentialSignals = cell(1,numEnabledBPChannels);
plotWindow = 5;
plotGain_BP = 1;
elapsedTime = 0;
tic;
while elapsedTime < duration
pause(0.08)
for ch = 1:numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};sin(t)];
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});
hold(axis_handles(ch),'on')
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));
hold(axis_handles(ch),'on')
xlim([t(end)-plotWindow t(end)])
end
end
elapsedTime = elapsedTime + toc;
tic;
end
BioRadioData = cell(1,1);
BioRadioData{1} = BioPotentialSignals;
これで、すべてのプロットラインが4番目のサブプロットに表示されました。私はそれが最初のforループと関係があるかもしれないと思う、他のサブプロットをクリアする – IamTrent
cla(axis_handles(ch))を2つのインスタンスで呼び、両方を変更しましたか? – JCKaz
また、サブプロットを作成した直後にプロットすることはできませんか?可能であれば、最初のループですべてを行います。 – JCKaz