0
votes

Using the function imagesc in Matlab, I plot my (X,Y, Z) data-X array distance, Y array time, and my data Z = Z(X,Y) a matrix.

I notice that the 80% of the image has one color, because the change of Z data occurred only in the end of X for almost all Y.

Right now I use colormap('hsv') which give I think the largest range of different colors.

I need to change the colorbar range to a logarithmic one to improve visual the range of the change of my output data through time along the distance X.

I have used also contourf but still I am not sure if it will better to use this function and not imagesc which the output is more smoothed.

Please, any idea, any method or any small script that I could use to show visual the difference in data in logarithmic scale in 2D using imagesc or another build in function is more than welcome! thank you

1
Would just imagesc(x,y,log(z)) work?chessofnerd
no, I have tried that, give an error: "Invalid datatype for Image CData. Numeric or logical matrix required for image CData."user1640255
I do not wish to change that data, but I would like to change the color that represent the data, to have a colorbar with a logarithmic scale, using imagescuser1640255

1 Answers

0
votes

There is a discussion at the Mathworks website where someone provided a function that does logarithmic color bars.

https://www.mathworks.com/matlabcentral/newsreader/view_thread/152310

EDIT: copying and pasting code from link

function cbar = colorbar_log(my_clim)
%COLORBAR_LOG Apply log10 scaling to pseudocolor axis 
% and display colorbar COLORBAR_LOG(V), where V is the
% two element vector [cmin cmax], sets manual, logarithmic
% scaling of pseudocolor for the SURFACE and PATCH
% objects. cmin and cmax should be specified on a LINEAR
% scale, and are assigned to the first and last colors in
% the current colormap. A logarithmic scale is computed,
% then applied, and a colorbar is appended to the current
% axis.
%
% Written by Matthew Crema - 7/2007

% Trick MATLAB by first applying pseudocolor axis
% on a linear scale
caxis(my_clim)

% Create a colorbar with log scale
cbar = colorbar('Yscale', 'log');

% Now change the pseudocolor axis to a log scale.
caxis(log10(my_clim));

% Do not issue the COLORBAR command again! If you want to
% change things, issue COLORBAR_LOG again.