wait for colormapeditor to close

3 次查看(过去 30 天)
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 个评论
André
André 2018-4-18
编辑:André 2018-4-18
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.

请先登录,再进行评论。

回答(2 个)

Catarina Moura
Catarina Moura 2020-8-27
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 个评论
y C
y C 2022-3-3
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

请先登录,再进行评论。


Robin Larsson Nordström
编辑:Robin Larsson Nordström 2023-11-6
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')

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by