wait for colormapeditor to close

3 views (last 30 days)
André
André on 18 Apr 2018
Unfortunately the function colormapeditor doesn't accept output arguments. It happens that I need to freeze the program flow until the dialogue box of the colormap editor closes. I need to retrieve the colormap created here and use it on multiple axes. So I need to wait until the colormap editor finishes its job. Using waitfor(colormapeditor) doesn't work. Anybody knows a workaround for this?
Many thanks
  1 Comment
André
André on 18 Apr 2018
Edited: André on 18 Apr 2018
I found a workaround here which I am adopting for now.
Still, I would like a more orthodox way of solving this problem, without forcing the user to make an additional press.

Sign in to comment.

Answers (2)

Catarina Moura
Catarina Moura on 27 Aug 2020
Hello André,
I don't know if you managed to solve it, but here is my solution to workaround this issue.
I created a button to open colormapeditor. The button callback uses copyUIAxes. Basically, the current plot is copied as a "normal" figure (which is hidden during all process).
app.fig = figure;
app.fig.Visible = 'off';
copyUIAxes(app.UIAxes,app.fig);
colormap(app.fig,originalcolormap); % original colormap is the current colormap
colormapeditor;
I didn't find a good way to update the plot's colormap once the colormapeditor is closed... I tried using a "while" but then the colormapeditor was impossible to acess. However, I have a button "plot". So basically, the user has to click on "plot" button so the colormap updates. I created a private function to return the final colormap from the figure, like this:
figaxes = app.fig.CurrentAxes;
app.currCM = get(figaxes,'colormap'); %global variable to access it in any function of the code
In my case, the user also has the option to choose from MATLAB's colormaps - a drop down menu. So basically I use "clock" to save the time that the colormap was changed (for both colormapeditor button callback and drop down menu callback) and when the user clicks "plot", the times are compared and the most recent is chosen.
Sadly, I could not find a way to update the plots with the new colormap automatically.
  1 Comment
y C
y C on 3 Mar 2022
Hello Catarina Moura :
I found sometimes my coloemapeditor become larger,and I can't change its size,I click it one time ,it bacome larger than before,I tried to reopen matlab ,but it don't work.sometimes coloemapeditor functions well,but everytime this problem happens,I don't know how to deal it.
Thanks a lot

Sign in to comment.


Robin Larsson Nordström
Robin Larsson Nordström on 6 Nov 2023
Edited: Robin Larsson Nordström on 6 Nov 2023
Hi,
Adding a listener for the colormapeditor event EditorClosed works in 2023b (undocumented feature, so might stop working in a later release).
Code below opens the colormapeditor pointing to the current axes. When closed it retrives the user selected colormap and updates all axes in the current figure with the selected colormap using an anonymous function.
h_currentFigure=gcf;
h_currentAxes=gca;
colormapeditor(h_currentAxes);
cme=getappdata(0,'CMEditor');
addlistener(cme.ColormapEditor,'EditorClosed',@(src,event)colormap(h_currentFigure,colormap(h_currentAxes)));
If you need the program to wait this could be done by adding another listener with the callback uiresume and then calling uiwait to make the program pause until the user have closed the colormapeditor.
colormapeditor;
cme=getappdata(0,'CMEditor');
addlistener(cme.ColormapEditor,'EditorClosed',@(src,event)uiresume);
disp(string(datetime("now")) + ' colormapeditor opened')
uiwait % pause program, wait for callback uiresume
disp(string(datetime("now")) + ' colormapeditor closed')

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!