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!

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
編集済み: Ameer Hamza 2020 年 4 月 3 日

0 投票

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 件のコメント

Steffi
Steffi 2020 年 4 月 3 日
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
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
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.
Steffi
Steffi 2020 年 4 月 3 日
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. :(
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
Can you show the output of
which histogram
Steffi
Steffi 2020 年 4 月 3 日
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;
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
This doesn't seem like the file provided by MATLAB. Have you placed some other function named histogram in MATLAB's path?
Steffi
Steffi 2020 年 4 月 3 日
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?
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
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?
Steffi
Steffi 2020 年 4 月 3 日
just downloaded new matlab version including toolbox and it works perfectly well now!
thanks a million!
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
Glad to be of help.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

タグ

質問済み:

2020 年 4 月 3 日

コメント済み:

2020 年 4 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by