私はこの関数を以前に使用していたと確信しています。 。 mathworks.comからサンプルコードを実行することすらできません。MATLAB var(A)と平均(A)エラー...添え字インデックスは正の整数または論理値のいずれかでなければなりません
Variance of Matrix
Create a matrix and compute its variance.
A = [4 -7 3; 1 4 -2; 10 7 9];
var(A)
Copyright 2015 The MathWorks, Inc.
は私を与える:
添字インデックスは、実際の正の整数 または論理名のいずれかでなければなりません。
これは、それだけで平均と分散計算にエラーが発生します...私の特定のコードです:
%2a
% Create distribution objects with different parameters
pd1 = makedist('Uniform','lower',-2,'upper',3)
% Compute the pdfs
x = -3:0.1:4;
pdf1 = pdf(pd1,x);
% Plot the pdfs
subplot(2,2,1);
plot(x,pdf1)
title('pdf of uniform RV [-2,3]');
ylim([0 0.3]);
% Compute the cdfs
x = -3:.01:4;
cdf1 = cdf(pd1,x);
% Plot the cdfs
subplot (2,2,2);
plot(x,cdf1)
title('CDF of uniform RV[-2,3]');
ylim([0 1.1]);
up = 3
low = -2
mean = (1/2)*(low + up)
var = (1/12)*(up-low)^2
% Do an actual numeric simulation
N=100000;
A = random(pd1,N,1);
[count edges] = histcounts(A,100);
count = [0 count 0];
edges = [-2.1 edges 3];
subplot(2,2,3)
plot(edges(2:end),count/N)
axis([-4 4 0 .02])
CDF = cumsum(count/N);
subplot(2,2,4)
plot(edges(2:end),CDF)
axis([-4 4 0 1.2])
m1 = sum(A)/N
v1 = var(A,0,1)
% Create distribution objects with different parameters
pd2 = makedist('Normal','mu',2,'sigma',sqrt(2.25))
% Compute the pdfs
x = -3:0.1:7;
pdf1 = pdf(pd2,x);
% Plot the pdfs
subplot(2,2,1);
plot(x,pdf1)
title('pdf');
axis([-4 7 0 .05])
ylim([0 0.3]);
% Compute the cdfs
x = -3:.01:4;
cdf1 = cdf(pd2,x);
% Plot the cdfs
subplot (2,2,2);
plot(x,cdf1)
title('CDF');
axis([-4 7 0 1.2])
%ylim([0 1.1]);
up = 3
low = -2
mean = (1/2)*(low + up)
var = (1/12)*(up-low)^2
% Do an actual numeric simulation
N=100000;
A = random(pd2,N,1);
[count edges] = histcounts(A,100);
count = [0 count 0];
edges = [-2.1 edges 3];
subplot(2,2,3)
plot(edges(2:end),count/N)
axis([-4 7 0 .05])
CDF = cumsum(count/N);
subplot(2,2,4)
plot(edges(2:end),CDF)
axis([-4 7 0 1.2])
m2 = mean(A)
v2 = var(A)