Matlab GUI未显示折线图图形数据

时间:2019-06-15 03:56:10

标签: matlab graph matlab-guide line-plot matlab-gui

我正在使用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))

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

1 个答案:

答案 0 :(得分:0)

我认为我发现了问题:

替换: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);

Not plotting


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

以下示例未作图:

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;

Plotting