pcolor - how to remove NaN text / string
Show older comments
Hi all,
I'm having a problem with pcolor plot where "I don't want to display NaN value" in my plot (figure attached). I only want to show real values. My code as follow and example of data is attached too. Maybe I should use other function instead of num2str? Any advise and suggestion would be very great! appreciate your time.
figure
H = pcolor(xedges,yedges,Ab);
colormap(cm);
set(H, 'linestyle', 'none');
pos=get(gca,'position'); % get plot position
[rows,cols]=size(Ab); % get cols and rows size
width=pos(3)/(cols-1); % get width and height positions
height =pos(4)/(rows-1);
for i=1:cols-1 % plot text in the figure
for j=rows-1:-1:1 annotation('textbox',[pos(1)+width*(i-1),pos(2)+height*(j-1),width,height], ...
'string',num2str(Ab(j,i)),'LineStyle','none','HorizontalAlignment','center',...
'VerticalAlignment','middle');
end
end
set(gca,'Xlim',[0 30]);
set(gca,'XTick',[0:3:30]);
set(gca,'Ylim',[0 5]);
set(gca,'YTick',[0:1:5]);
set(gca,'FontSize',10,'FontWeight','Bold');
the code above is originally from here:
I've tried with index and add it in my code, I can get ride of NaN but now all values shown as 40. Can somebody please help me figure out this? (see second plot below)
idx = ~isnan(Ab);
for j=rows-1:-1:1 annotation('textbox',[pos(1)+width*(i-1),pos(2)+height*(j-1),width,height], ...
'string',num2str(Ab(idx(j,i))),'LineStyle','none','HorizontalAlignment','center',...
'VerticalAlignment','middle');
end
end


Thanks, Raydo
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion 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!