0
votes

So basically I have a GUI and i have an axis plot.

I want my graph to have an image which moves up and down when i click the calculate button. Would any one give me direction on how to go on about this? Using position command? Note that the figure corresponds to movement of a control system with a time response graph. Hence as system becomes stable the picture movement would come to a halt (certain position). So far my image do does not even appear on the axes!Any help would be greatly appreciated on matlab!

for frame=1:1:length(t)
    if stop ~= 1
   axes(handles.axes5)
    cla;
    hold on;

    if y(frame)<=0


axes(handles.axes5,'position',[3,y(frame)+0.001,3,((y(frame)+1.0000000001))]);
imshow('ball.jpg','position',[3,0.001,3,(1.00000000001)]);


    else

axes(handles.axes5,'position',[3,y(frame)+0.001,3,((y(frame)+1.0000000001))]);
imshow('ball.jpg','position',[3,y(frame)+0.001,3,((y(frame)+1.0000000001))]);


    end
1
so this code is in the pushbutton callback? What is y?Benoit_11
y corresponds to the time solution plot which is a step input graph of the form [y,t]=step(sys); axes(handles.axes5) axis([0,9,0,20])aqw

1 Answers

0
votes

I suspect your image is not showing due to the process being busy.

If you have a gui which is updated during a process you need to tell Matlab to redraw. You do this by including the command

drawnow

Put this after you update the image position.

edit Update with example of moving axes.

d = figure;
ax = axes ( 'parent', d );
I = imread('pout.tif');
imshow ( I, 'parent', ax );

offset = 0.01;
for i=1:1000
  position = get ( ax, 'position' );
  position(1) = position(1) + offset;
  % if image off right hand side of page - change offset
  if position(1) + position(3) >=1
    offset = -offset;
    % if image off left hand side of page - change offset
  elseif position(1) <= 0
    offset = -offset;
  end
  set ( ax, 'position', position );
  drawnow()  
end

There are a lot of questions regarding your code to fix it exactly:

A few points for you to consider:

  1. Axes units are "usually" normalized - maybe you have changed that in your code - its unclear.
  2. You should load your image before the loop, rather than load it each time you call imshow.
  3. Its advisable to explicitly state which axes you want to perform an action on (e.g. the parent call above) - yours would be handle.axes5
  4. You dont need to refreseh the whole plot in the loop (cla, hold on etc...), just move the axes.