MATLAB Answers

Plotting bar graph for loop values

38 ビュー (過去 30 日間)
Hari krishnan
Hari krishnan 2019 年 5 月 16 日
編集済み: Hari krishnan 2019 年 5 月 17 日
I am trying to make a barplot of the values in vector's 'count_gn', 'count_bn', 'count_hn' and 'count_ar' as a seperate subplots. I tried using 'bar' function for the purpose. But i am not seeing any barplots.
Can anyone suggest a method to do seperate barplots for the values in the vector 'count_gn', 'count_bn', 'count_hn' and 'count_ar' ?
Any help to solve this will be appreciated.
tic
a = smoothed_final_plot_mat(1:end-2033,3:end-2);
np = (size(a,2)-1)/2; % number of particles
t = a(2:end,1);
arena_image = imread('arena_pic_gn_top.png');
subplot(1,2,1)
h1 = axes ;
cc = hsv(np);
image('XData',[0 6900],'YData',[0 5000],'CData',arena_image) ; % set your limits
set(h1,'YDir','normal');
dim = [0.79, 0.825, 0.2, 0.1];
annotation('textbox',dim);
t1 = uicontrol('Style','text','String','Select a data set.','Position',[1550 790 300 80],'FontSize',13,'HorizontalAlignment','left');
ax = gca;
ax.YDir = 'reverse';
axis([0 6900 0 5000])
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
h = zeros(1,np);
for ii = 2:25:size(a,1)
ax.Position(3) = 0.65;
k = 0;
t = a(ii,1);
count_gn(ii,1) = rowsum_for_ants_in_gdnest_matrix(ii); %#ok<SAGROW>
count_bn(ii,1) = rowsum_for_ants_in_bdnest_matrix(ii); %#ok<SAGROW>
count_hn(ii,1) = rowsum_for_ants_in_arena_except_homenest(ii); %#ok<SAGROW>
count_ar(ii,1) = rowsum_for_ants_in_field(ii); %#ok<SAGROW>
hold on
for jj = 2:2:np*2 % ant handles
x = a(ii,jj);
y = a(ii,jj+1);
k = k + 1;
h(k) = plot(x,y,'--or');
hi(k) = text(x, y, label(k), 'VerticalAlignment','bottom', 'HorizontalAlignment','right'); %#ok<SAGROW>
h2(k) = plot(a(max(1,ii-150):ii,jj), a(max(1,ii-150):ii,jj+1),'k','LineWidth',2); %#ok<SAGROW>
set(h2(k),'color',cc(k,:));
end
drawnow
pause(0.01)
delete(h)
delete(hi)
delete(h2)
disp(k)
end
toc

  2 件のコメント

TADA
TADA 2019 年 5 月 16 日
I randomized some data and got a barchart,
so may be the problem is with your data
try checking if there are NaN value in there, if you are summing them, the default behaviour of sum is to return NaN when it sums NaN with the numbers.
If so, you can try using
x = [magic(3) nan(3,1)];
sum(x, 2)
sum(x, 2, 'omitnan')
ans =
NaN
NaN
NaN
ans =
15
15
15
Hari krishnan
Hari krishnan 2019 年 5 月 17 日
Hi, i checked the data throughly, there is no NaN in the data. Also when i try to use 'bar' one of the axis always keeps on moving.

サインインしてコメントする。

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by