Matlab GUI 不显示线图数据

Matlab GUI not showing line plot graph data

我正在使用我的 Matlab GUI 文件播放视频并绘制颜色通道 (RGB) 的平均值。它有 2 个轴,第一个用于视频播放器,第二个轴用于平均图,但第二个轴不显示任何数据,它只是更新 x 和 y 坐标但不显示任何内容。

我尝试更改手柄,更改 属性 检查器中的下一个绘图设置,但它不起作用

function main_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;
video = vision.VideoFileReader();
handles.video = video;
frameCount = 0;
handles.frameCount = frameCount;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.

function varargout = main_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
handles.output = hObject;
varargout{1} = handles.output;
% --- Executes on button press in Browse.

function Browse_Callback(hObject, eventdata, handles)
% hObject    handle to Browse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[ video_file_name,video_file_path ] = uigetfile({'*.avi'},'Pick a video file');      %;*.png;*.yuv;*.bmp;*.tif'},'Pick a file');
if(video_file_path == 0)
    return;
end
input_video_file = [video_file_path,video_file_name];
fullpath = strcat(video_file_path,video_file_name);
set(handles.edit1,'String',fullpath);
video = vision.VideoFileReader(input_video_file);
vidFrame = step(video);
axes(handles.axes1);set(handles.StartButton,'String','Start');
frameCount = 1;
imshow(vidFrame);
drawnow;
axis(handles.axes1,'off');
   for nChannel = 1:3
       colorChannel = vidFrame(:,:,nChannel);
       rawColorSignal(nChannel,frameCount) =  mean(mean(colorChannel));
   end

%plot(frameCount,rawColorSignal(1, :),frameCount,rawColorSignal(2, :),frameCount,rawColorSignal(3, :), handles.axes2);
axes(handles.axes2)
plot(frameCount,rawColorSignal(1, :));
grid on
drawnow;
axes(handles.axes1)
% Display Frame Number
%Update handles
handles.video = video;
guidata(hObject,handles);

% --- Executes on button press in StartButton.
function StartButton_Callback(hObject, eventdata, handles)
% hObject    handle to StartButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if strcmp(get(handles.StartButton,'String'),'Pause')
    set(handles.StartButton,'String','Start');
else
    set(handles.StartButton,'String','Pause');
end
video = handles.video;
if  isDone(video)
    reset(video)
    frameCount = 0;
    handles.frameCount = frameCount;
end
frameCount = handles.frameCount;
 while ~isDone(video) && strcmp(get(handles.StartButton,'String'),'Pause')
     vidFrame   = step(video);
     imshow(vidFrame,'Parent',handles.axes1); %plot frame is specific axis
     drawnow;
    frameCount = frameCount + 1;
    for nChannel = 1:3
       colorChannel = vidFrame(:,:,nChannel);
       rawColorSignal(nChannel,frameCount) =  mean(mean(colorChannel));
    end

    plot(frameCount,rawColorSignal(1, :),'Parent',handles.axes2);
    grid on
    drawnow;
 end

%plot(frameCount,rawColorSignal(1, :),'r',frameCount,rawColorSignal(2, :),'g',frameCount,rawColorSignal(3, :),'b','Parent', handles.axes2);
%drawnow;
 set(handles.StartButton,'String','Start');
% --- Executes on button press in PauseButton.
function PauseButton_Callback(hObject, eventdata, handles)
% hObject    handle to PauseButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%axes(handles.axes2)
%surf(membrane(3))

我期望的是线图是可见的并且沿着轴更新。

我想我发现了问题:

替换:plot(frameCount,rawColorSignal(1, :));
随着:plot(1:frameCount,rawColorSignal(1, :));

替换:plot(frameCount,rawColorSignal(1, :),'Parent',handles.axes2);
随着:plot(1:frameCount,rawColorSignal(1, :),'Parent',handles.axes2);


plot(frameCount,...使用标量 frameCount 作为 X 坐标。
您希望绘图中的 X 坐标是从 1frameCount 的向量。

如果出现错误,请尝试:
plot(1:length(rawColorSignal(1, :)), rawColorSignal(1, :), 'Parent', handles.axes2);


我创建了以下示例代码来演示问题:

以下示例未绘制:

frameCount = 0;
rawColorSignal = [];

for i = 1:10
    frameCount = frameCount + 1;
    rawColorSignal(frameCount) =  i;
end

plot(frameCount, rawColorSignal);
grid on
drawnow;

plot(frameCount, rawColorSignal); 替换为 plot(1:frameCount, rawColorSignal); 时:

frameCount = 0;
rawColorSignal = [];

for i = 1:10
    frameCount = frameCount + 1;
    rawColorSignal(frameCount) =  i;
end

plot(1:frameCount, rawColorSignal);
grid on
drawnow;