Error using histc Edge vector must be monotonically non-decreasing.
6 次查看(过去 30 天)
显示 更早的评论
Hi
I have the following code and data;
clc
clear all
datapoint = [0; 2; 0; 2; 5; 8; 7; 10; 21; 38; 51; 53; 84; 93; 115; 123; 134];
for j =1:length(datapoint)
value =datapoint(j);
for i = 1:value
xpos(i,j) = 600*rand();
ypos(i,j) = -1.75+ 3.5*rand();
end
end
xpos(xpos==0)=nan;
ypos(ypos==0)=nan;
label = 1200:100:2800;
%% Spatial distribution
for k = 1:17
ax(i) = subplot(1,17,k);
values = hist3([ypos(:,k) xpos(:,k)],[4 60]);
V = values.';
Vq = interp2(V,5);
imagesc(Vq);
%grid on
caxis([0 7]);
if k == 1
axis on
else
set(gca,'yticklabel',{[]})
end
set(gca,'xticklabel',{[]})
xlabel(label(1,k));
end
Once I ran it, I got the error in title. Can someone help me to solve the problem?
I am supposed to get the figure like following. Other codes to plot similar figure can also help.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292627/image.png)
0 个评论
回答(1 个)
Sindhu Karri
2020-5-19
Hii,
The error is due to following code lines:
xpos(xpos==0)=nan;
ypos(ypos==0)=nan;
By modifying these lines as below
xpos(xpos==0)= 0;
ypos(ypos==0)= 0;
You can avoid the error and get the desired plot
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!