Generating a histogram from a cell array using cell2mat
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert Pearhill
am 7 Dez. 2021
Kommentiert: Robert Pearhill
am 7 Dez. 2021
Hi All,
I am attempting to generate a histogram from a cell array using the cell2mat function. Using the code below, I am receiving the following error:
Error using histogram>parseinput (line 306)
Trailing input arguments must occur in name-value pairs.
Error in histogram (line 145)
[opts,passthrough,dispatchToCategorical] = parseinput(args,firstaxesinput);
Error in untitled (line 51)
histogram (R0array,[0:0.1:3],"probability");
I am very new to coding in matlab, and I assumed that once I transitioned the cell array to a double array the histogram would play nice. I am confused by what is meant by a "name-value pair." Any help would be greatly appreciated!
%Total number of replicates
n=1000;
%Generating cells to store results
result=cell(n,1);
%Generating cells to store values for R0
R0result=cell(n,1);
%Figure hold to plot all 1000 replicates on a single graph
figure; hold on
%Latin hypercube with 1000 values generated for 11 parameters
LHS=lhdesign(1000,11);
for k=1:n
%Initial conditions
n=16956;
y20=10;
y30=0;
%Parameters I am hoping to sample randomly using LHS instead of "rand"
p=(407-341)*rand+341;
d=(1/42-1/50)*rand+1/50;
yc=(4.923*10^-3-8.8*10^-5)*rand+8.8*10^-5;
yi=(4.923*10^-3-8.8*10^-5)*rand+8.8*10^-5;
a=(1/30-1/120)*rand+1/120;
r=(0.30-.10)*rand+0.1;
i=(1/4-1/15)*rand+1/15;
bc=(1.5*10^-3-1.5*10^-5)*rand+1.5*10^-5;
bi=(1.5*10^-3-1.5*10^-5)*rand+1.5*10^-5;
c=(50-5)*rand+5;
tr=(0.2-0.01)*rand+0.01;
%Time step and length
tspan=[(1:0.1:500)];
%Function definition
[t,y] = ode23s(@(t,y) [p*(1-yc-yi) + a*y(2) + tr*y(3) - (c*bc*y(2)*y(1))/n - (c*bi*y(3)*y(1))/n - d*y(1); p*yc + (c*bc*y(2)*y(1))/n + (c*bi*y(3)*y(1))/n - a*y(2) - r*i*y(2) - d*y(2); p*yi + r*i*y(2) + - d*y(3)-tr*y(3);], tspan, [n y20 y30]);
%Storing results in cells
result{k} = y;
%Graphing all replicates for y(2).
plot(t, y(:,2));
%Generating an R0 for each iteration of the random parameters
R0 = (c*bc+r*i*c*(bi/d))/(a+r*i+d);
R0result{k}= R0;
end
histogram (R0array,[0:0.1:3],"probability");
R0array = cell2mat(R0result);
2 Kommentare
Akzeptierte Antwort
Atsushi Ueno
am 7 Dez. 2021
histogram(___,Name,Value) specifies additional options with one or more Name,Value pair arguments using any of the previous syntaxes. For example, you can specify 'BinWidth' and a scalar to adjust the width of the bins, or 'Normalization' with a valid option ('count', 'probability', 'countdensity', 'pdf', 'cumcount', or 'cdf') to use a different type of normalization. For a list of properties, see Histogram Properties.
So, you need additinal property name 'Normalization'.
histogram (R0array,[0:0.1:3],'Normalization','probability');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!