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

조회 수: 25 (최근 30일)
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

채택된 답변

Jeffrey Clark
Jeffrey Clark 2022년 9월 15일
@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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by