After editing an existing colormap with the colormapeditor, I want to save it. The documentation states that I should do something like:
mycmap = get(fig,'Colormap');
However, the saved colormap, mycmap, has the original colormap data not the eddited one. Here's a minimal example:
imagesc(peaks(10));
colormap(hot(6))
Now go into the figure's gui colormap editor using >Edit>Colormap and only change yellow to blue. Now after that press Apply see that indeed the figure has changed. Now write on the command line:
mycmap = get(gcf,'Colormap')
mycmap =
0.5000 0 0
1.0000 0 0
1.0000 0.5000 0
1.0000 1.0000 0
1.0000 1.0000 0.5000
1.0000 1.0000 1.0000
there no "blue" ([0 0 1]) color. Interestingly, when the figure is saved the colormap is saved with it, but for some reason I cant access the edited colormap. What am I doing wrong? (I'm using Matlab 2014b)

 채택된 답변

Adi Natan
Adi Natan 2015년 10월 12일

14 개 추천

It looks like the colormap is now associated with the axes rather than the figure. So,
cmap = colormap(gca);
will retrieve the edited map.

댓글 수: 3

Walter Roberson
Walter Roberson 2015년 10월 12일
So I provided the correct solution but don't even get a vote? :(
Adi Natan
Adi Natan 2015년 12월 28일
saying "So use gca" is a very partial answer. I had to go and investigate how one should use gca, and that was far from the regular way gca is usually used (i.e. set(gca...) ). that is why I felt I had to write the full answer.
Zhao-Yang CHAI
Zhao-Yang CHAI 2018년 5월 3일
Very useful! I have met the same problem and maybe it's a bug. It's strange that the colormaps of gca and gcf are different.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2015년 10월 10일

6 개 추천

Starting in R2014b, colormaps are per-axes rather than per-figure. So use gca (or some other way of identifying the axes) instead of gcf .

댓글 수: 2

hamed amini
hamed amini 2018년 5월 26일
mycbar= get(gca,Colormap'); % this works
set(gcf,'Colormap',mycbar); %this works
set(gca) does not work in R2017a. This does not sound right and is confusing.
Walter Roberson
Walter Roberson 2018년 6월 6일
편집: Walter Roberson 2018년 6월 6일
?
set(gca, 'Colormap', mycbar)
works

댓글을 달려면 로그인하십시오.

Sean de Wolski
Sean de Wolski 2015년 7월 9일

0 개 추천

Is gcf, the same as fig?

댓글 수: 6

Adi Natan
Adi Natan 2015년 7월 9일
the input of get command assumes there is an object to get. fig is just a name you can give a figure object. When a figure is open the gcf (get current figure) is that object. If you try just get(fig...) you'll get an error. Also, why are you using the answer to give a comment? You sis answer the question, you just had a comment.
Sean de Wolski
Sean de Wolski 2015년 7월 9일
No, my question will possibly point you to what's wrong. gcf is the current figure which may not be the same as the figure you modified :)
Sean de Wolski
Sean de Wolski 2015년 7월 9일
However, I am able to reproduce this behavior. I would've expected either the Colormap or the CDataMapping of the Image to have changed by using the colorbareditor but you're right it doesn't appear to be changing anything.
Adi Natan
Adi Natan 2015년 7월 9일
well, that's not surprising. I just hope other people would still look at this question, even though there seems to be an "answer" though it is still not answered.
Ken
Ken 2015년 10월 10일
I have the same problem! This is a bug that needs fixing, or a good explaination
Adi Natan
Adi Natan 2015년 10월 12일
I found the answer, see below...

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Red에 대해 자세히 알아보기

제품

질문:

2015년 7월 9일

편집:

2018년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by