plotting multiple histograms from data saved as double

hey guys..
I am trying to get 30 subplots with each 3 (differently coloured) histograms from column 1:3 of each row of the attached dataset saved as double.
tried hist but this wouldnt let me change the colour....histogram didnt work with double/cell array i think.
I am new to matlab...anyone could help? using matlab 2019b.
thanks!

 Accepted Answer

There are 29 rows in the cell array you attached.
colors = [1 0 0;
0 1 0;
0 0 1];
fig = figure();
ax = gobjects(1, 30);
for i = 1:size(P_RTpertrial,1)
ax(i) = subplot(10,3,i);
hold(ax(i));
for j = 1:size(M, 2)
histogram(P_RTpertrial{i,j}, 'FaceColor', colors(j,:), 'FaceAlpha', 0.3);
end
end
fig.WindowState = 'maximized';

10 Comments

hey thanks a lot for your answer...
hmmm unfortunately I get an error code "Error using histogram, Too many input arguments."
also I wonder...they should all look different...
is it ...
M = [P_RTpertrial{i,:}]; ?
but even then I get an error in the histogram line...(see above)
grrrr
Yes, you are correct. It should have been
M = [P_RTpertrial{i,:}];
but this won't work because matrices have a different number of rows. I have updated the code, try it now.
I have now also replace M with P_RTpertrial....but I still get "Error using histogram, Too many input arguments." when I get to the "histogram"-line. :(
Can you show the output of
which histogram
shows me the path to the following file:
function [result,descriptor]=histogram(x,descriptor)
% HISTOGRAM Computes the frequency histogram of the row vector x.
% [RESULT,DESCRIPTOR] = HISTOGRAM(X) or
% [RESULT,DESCRIPTOR] = HISTOGRAM(X,DESCRIPTOR) or
%where
% DESCRIPTOR = [LOWER,UPPER,NCELL]
%
% RESULT : A row vector containing the histogram
% DESCRIPTOR: The used descriptor
%
% X : The row vector be analyzed
% DESCRIPTOR: The descriptor of the histogram
% LOWER : The lowerbound of the histogram
% UPPER : The upperbound of the histogram
% NCELL : The number of cells of the histogram
%
% See also: http://www.cs.rug.nl/~rudy/matlab/
% R. Moddemeijer
% Copyright (c) by R. Moddemeijer
% $Revision: 1.2 $ $Date: 2001/02/05 09:54:29 $
if nargin <1
disp('Usage: RESULT = HISTOGRAM(X)')
disp(' RESULT = HISTOGRAM(X,DESCRIPTOR)')
disp('Where: DESCRIPTOR = [LOWER,UPPER,NCELL]')
return
end
% Some initial tests on the input arguments
[NRowX,NColX]=size(x);
if NRowX~=1
error('Invalid dimension of X');
end;
if nargin>2
error('Too many arguments');
end;
if nargin==1
minx=min(x);
maxx=max(x);
delta=(maxx-minx)/(length(x)-1);
ncell=ceil(sqrt(length(x)));
descriptor=[minx-delta/2,maxx+delta/2,ncell];
end;
lower=descriptor(1);
upper=descriptor(2);
ncell=descriptor(3);
if ncell<1
error('Invalid number of cells')
end;
if upper<=lower
error('Invalid bounds')
end;
result(1:ncell)=0;
y=round( (x-lower)/(upper-lower)*ncell + 1/2 );
for n=1:NColX
index=y(n);
if index >= 1 & index<=ncell
result(index)=result(index)+1;
end;
end;
This doesn't seem like the file provided by MATLAB. Have you placed some other function named histogram in MATLAB's path?
got this version from my colleauges...have looked online to download the original version....but didnt find anything...do you know where to best get it?
You cannot get it online. This only comes with the installation of MATLAB. Does the path shows that it lies somewhere like
C:\....\MATLAB\toolbox\....
or the file is placed somewhere else?
just downloaded new matlab version including toolbox and it works perfectly well now!
thanks a million!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!