How to solve 'Error using image Complex values are not supported. Specify the color data as numeric or logical values.'

16 views (last 30 days)
Hi
I have attached my data S_OPT.mat having size SW_OPT (115 200) and VD (115 1);
The problem is some array in SW_OPT are complex number and I want to plot probability as given by my code:
x22 = [0.0:0.001:1]';
Prob_SW = zeros(length(VD), length(x22));
for i=1:length(VD)
Prob_SW(i,:) = ksdensity(SW_OPT(i,:),x22);
Prob_SW(i,:) = Prob_SW(i,:)/sum(Prob_SW(i,:));
end
figure(6), imagesc([0.0:0.001:1], VD, Prob_SW); xlabel('S_w (m/s)');
axis([1 1 1.888e+03 2.131e+03]); set(gca,'ytick',[1.888e+03:55:2.131e+03]);
set(gca,'xtick',[0:0.5:1]); set(gca,'FontSize',9); ylabel('Depth (m)'); colorbar;
set(gcf, 'position', [1200 285 200 410]);
colorbar;
But following error appears
Error using image
Complex values are not supported. Specify the color data as numeric or logical values.
Error in imagesc (line 52)
hh = image(varargin{:}, 'CDataMapping', 'scaled');
Error in UQ_PLOT_4D (line 195)
figure(6), imagesc([0.0:0.001:1], VD, Prob_SW); xlabel('S_w (m/s)');
How can I solve this problem? I want to obtain a figure like this

Accepted Answer

Jeffrey Clark
Jeffrey Clark on 15 Sep 2022
@Nisar Ahmed, I don't have the toolbox for ksdensity but the imaginary parts of SW_OPT are insignificant relative to their real and abs values. I think you should instead be using abs(SW_OPT) and your imaginary problem will be resolved.

More Answers (0)

Categories

Find more on Images 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!