2014-01-22 6 views
2

나는 576x576x150 매트릭스를 가지고 있습니다. 각 576x576 세트는 이미지를 나타냅니다. 나는 하나 개의 프레임을 플롯 할 때 나는 플롯 명령을 사용하여 그것을 할 : 나는 음모에 슬라이더를 추가하고 싶습니다, 그래서 나는 figure.I '내 1-150 프레임에서 이동할 수 그러나그림에 슬라이더를 추가하는 MATLAB

figure(1); 
imshow(B(:,:,45),[]) % plots frame 45 
title('45') % tells frame number 

uicontrol을 사용하는 사람들의 예를 보았지만 코드 작성법을 모르겠습니다. 그 외에도 프레임 번호를 알려주는 그림 상단에 제목을 표시하고 싶습니다.

+0

관련 : http://stackoverflow.com/questions/15975758/matlab-simple-slider-on-a-figure – herohuyongtao

답변

1

내가 그것을 할 방법이다. 필자는 다른 곳에서 명령을 재활용하지 않도록 플로팅을 수행하는 단일 기능을 유지하려고합니다. 처음 두 행을 function test(B)으로 바꾸면 B 행렬을 소유 할 수 있습니다. 이 코드는 쉽게 확장 할 수 있습니다. 또한 목적에 맞게 레이아웃을 가지고 놀고 싶을 것입니다.

function test 
B=rand(576,576,150); 

fig=figure(100); 
set(fig,'Name','Image','Toolbar','figure',... 
    'NumberTitle','off') 
% Create an axes to plot in 
axes('Position',[.15 .05 .7 .9]); 
% sliders for epsilon and lambda 
slider1_handle=uicontrol(fig,'Style','slider','Max',150,'Min',1,... 
    'Value',2,'SliderStep',[1/(150-1) 10/(150-1)],... 
    'Units','normalized','Position',[.02 .02 .14 .05]); 
uicontrol(fig,'Style','text','Units','normalized','Position',[.02 .07 .14 .04],... 
    'String','Choose frame'); 
% Set up callbacks 
vars=struct('slider1_handle',slider1_handle,'B',B); 
set(slider1_handle,'Callback',{@slider1_callback,vars}); 
plotterfcn(vars) 
% End of main file 

% Callback subfunctions to support UI actions 
function slider1_callback(~,~,vars) 
    % Run slider1 which controls value of epsilon 
    plotterfcn(vars) 

function plotterfcn(vars) 
    % Plots the image 
    imshow(vars.B(:,:,get(vars.slider1_handle,'Value'))); 
    title(num2str(get(vars.slider1_handle,'Value'))); 
+0

나는를 포함하는 부하 ('frames.mat')과 두 번째 줄을 교체 B (576,576,150) 매트릭스가 작동하지 않습니다. S – Jorge

+0

그건 이상합니다! 어떤 오류가 발생하고 있습니까? – David

+0

오류는 없지만 모든 프레임이 흰색입니다 !!! 어쩌면 윈도우 문제입니다. i = min (min (B, [], 1))); ' 'b = max (max (B, [], 1)))'그리고 나서'imshow (B (:, :, frame), [ab])'하지만 그 코드에 코드를 추가하는 방법을 모르겠습니다. – Jorge

1

아이디어는 uicontrol()을 사용하여 슬라이딩/스크롤링을 활성화하는 것입니다.

다음 코드는 (당신이 슬라이딩 수정할 수 Evan Brooks에 의해 생성) 스크롤입니다 :

여기
function scrollfigdemo 

% create new figure window 
f = figure; 
set(f,'doublebuffer', 'on', 'resize', 'off') 

% set columns of plots 
cols = 2; 

% create 5 data sets to plot 
x=0:1e-2:2*pi; 
y{1}=sin(x); 
y{2}=cos(x); 
y{3}=tan(x); 
y{4}=x.^2; 
y{5}=x.^3; 

% determine required rows of plots 
rows = ceil(length(y)/cols); 

% increase figure width for additional axes 
fpos = get(gcf, 'position'); 
scrnsz = get(0, 'screensize'); 
fwidth = min([fpos(3)*cols, scrnsz(3)-20]); 
fheight = fwidth/cols*.75; % maintain aspect ratio 
set(gcf, 'position', [10 fpos(2) fwidth fheight]) 

% setup all axes 
buf = .15/cols; % buffer between axes & between left edge of figure and axes 
awidth = (1-buf*cols-.08/cols)/cols; % width of all axes 
aidx = 1; 
rowidx = 0; 
while aidx <= length(y) 
    for i = 0:cols-1 
     if aidx+i <= length(y) 
      start = buf + buf*i + awidth*i; 
      apos{aidx+i} = [start 1-rowidx-.92 awidth .85]; 
      a{aidx+i} = axes('position', apos{aidx+i}); 
     end 
    end 
    rowidx = rowidx + 1; % increment row 
    aidx = aidx + cols; % increment index of axes 
end 

% make plots 
axes(a{1}), plot(x,y{1}), title('sine'), xlabel('x'), ylabel('sin(x)') 
axes(a{2}), plot(x,y{2}), title('cosine'), xlabel('x'), ylabel('cos(x)') 
axes(a{3}), plot(x,y{3}), title('tangent'), xlabel('x'), ylabel('tan(x)') 
axes(a{4}), plot(x,y{4}), title('x^2'), xlabel('x'), ylabel('x^2') 
axes(a{5}), plot(x,y{5}), title('x^3'), xlabel('x'), ylabel('x^3') 

% determine the position of the scrollbar & its limits 
swidth = max([.03/cols, 16/scrnsz(3)]); 
ypos = [1-swidth 0 swidth 1]; 
ymax = 0; 
ymin = -1*(rows-1); 

% build the callback that will be executed on scrolling 
clbk = ''; 
for i = 1:length(a) 
    line = ['set(',num2str(a{i},'%.13f'),',''position'',[', ... 
      num2str(apos{i}(1)),' ',num2str(apos{i}(2)),'-get(gcbo,''value'') ', num2str(apos{i}(3)), ... 
      ' ', num2str(apos{i}(4)),'])']; 
    if i ~= length(a) 
     line = [line,',']; 
    end 
    clbk = [clbk,line]; 
end 

% create the slider 
uicontrol('style','slider', ... 
    'units','normalized','position',ypos, ... 
    'callback',clbk,'min',ymin,'max',ymax,'value',0); 
관련 문제