Update Imagesc on Button Press

9 views (last 30 days)
Sean
Sean on 17 Dec 2012
Hi,
I have a large matrix of values (1024x3533) that I am using to draw an image using imagesc. I am doing this with four subplots. On my computer, this takes approximately 60 seconds.
On two of the images, I am assigning certain rows to act as boundaries. For example, I might make
(300, :) = -30
(600, :) = -30
so that a yellow line appears at these rows.
I would like to have a button on my GUI that increases the indices of these lines when pressed. My y-axis is reversed, so when I press the button, the indices would "increase" to
(299, :) = -30
(599, :) = -30
This sounds simple enough in theory. However the way I am attempting it requires the entire image to be redrawn. So far I have not gotten this to work, and it is very hard to troubleshoot due to the size of the images being drawn, and the time it takes to draw them.
Is there a way I can simply redraw a portion of an image using imagesc? So for example, I would only redraw the boundary lines described above? Alternatively, is there a way to superimpose an image containing only the lines on top of the existing image?

Accepted Answer

Sean de Wolski
Sean de Wolski on 17 Dec 2012
Just update the 'CData' of the image. I.e:
myCData = get(hImage,'CData');
myCData(10,:) = pi;
set(hImage,'CData',myCData);
This will alleviate having to call the destructor for the existing image and the constructor for the new one which will save a bunch of time since the settings are all the same.
  2 Comments
Sean
Sean on 18 Dec 2012
Cool, this seems to be working. However, I am still having an issue with the "y-1 row" going back to its original value. Inside my pushbutton function, I have the following code:
myCDataOld = get(im_4,'CData');
myCData = myCDataOld;
myCData(yy,:) = -30;
myCData(yy - 1, :) = myCDataOld(yy - 1, :);
set(im_4,'CData',myCData);
yy = yy + 1;
Where myCDataOld has the original CData, and myCData contains the modified values. I would think that I should just be able to set myCData(yy-1,:) to myCDataOld(yy-1,:) as shown in the code, but this does not work. Instead, the line remains at each previous row in addition to the current row when I press the push button.
Sean
Sean on 18 Dec 2012
Nevermind, I think I just needed to set myCDataOld as a global outside of the pushbutton function. Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!