1

I do have generated two 2-D dimensional matrices from my core process. Now, I want to represent them via the bar graphs. I could manage to get the 3d bar graph for independant matrix as shown in figures attached.

xData bar3 figure

My data matrices are

  1. "xData" - size is : (52 x 46 )
  2. "yData" - size is : (52 x 46)

They'll always have the same size.

Now, I want to represent them together in 'Grouped Style' As show in here. I got the 3D dimensional matrix by combining them (xData and yData) together i.e. generated 52 x 46 x 2 matrix and then tried to plot with bar3 command; but, I got an error and couldn't plot. Do you guys have any idea on how to do it ?

Suever
  • 64,497
  • 14
  • 82
  • 101
adi
  • 11
  • 2
  • Can you provide us the exact Matlab code you used to create the showed graph and the code you tried with the exact error message? – m7913d Apr 11 '17 at 18:25
  • Possible duplicate of [Grouping bar3 plots like bar](http://stackoverflow.com/questions/5334088/grouping-bar3-plots-like-bar) – m7913d Apr 11 '17 at 18:32

1 Answers1

0

I manage to do that using a loop and this SO answer:

% generate random data
sz = [5 4];
xData = rand(sz);
yData = rand(sz);
% plot zeros in the same size to prepare plot
Z = zeros(sz);
h0 = bar3(Z);
set(h0,'EdgeColor','none','FaceColor','none');
axis tight
% plot each data column in a loop
hold on
for kk = 1:size(xData,2)
    h1 = bar3([xData(:,kk),yData(:,kk)],'grouped');
    % move current bars to their x position
    cellfun(@(x) set(h1,'XData', x + (kk - 1)), get(h1,'XData'));
end

enter image description here

Community
  • 1
  • 1
user2999345
  • 4,195
  • 1
  • 13
  • 20
  • Thanks @user2999345 looks like it would do the needful.. will update you accordingly – adi Apr 12 '17 at 09:29