我想绘制正态分布图,但在同一图中通过循环绘制多个图。对于第一次迭代,它的精细,即一个图中的3个图,但在其他3个图中,它只绘制一个。代码
load iris.dat;
iris;
number_of_features = 4;
classes = iris(:,5);
number_of_classes = length(unique(classes));
for class_number = 1:number_of_classes
likelihood{class_number} = struct;
for feature_number = 1:number_of_features
likelihood{class_number}.pd{feature_number} = fitdist(iris(find(iris(:, 5) == class_number),feature_number),'Normal');
end
end
hold all
for feature_number = 1:number_of_features
for class_number=1:number_of_classes
ppd=iris(find(iris(:, 5) == class_number),feature_number);
y=normpdf(ppd,likelihood{class_number}.pd{feature_number}.mu,likelihood{class_number}.pd{feature_number}.sigma);
figure(feature_number)
stem(ppd,y)
end
end
如果有人可以检查它并告诉我们代码中的问题
答案 0 :(得分:0)
我不确定,但下面的代码可能有效。我刚改变了你的命令。
load iris.dat;
iris;
number_of_features = 4;
classes = iris(:,5);
number_of_classes = length(unique(classes));
for class_number = 1:number_of_classes
likelihood{class_number} = struct;
for feature_number = 1:number_of_features
likelihood{class_number}.pd{feature_number} = fitdist(iris(find(iris(:, 5) == class_number),feature_number),'Normal');
end
end
for feature_number = 1:number_of_features
figure(feature_number)
hold on
for class_number=1:number_of_classes
ppd=iris(find(iris(:, 5) == class_number),feature_number);
y=normpdf(ppd,likelihood{class_number}.pd{feature_number}.mu,likelihood{class_number}.pd{feature_number}.sigma);
stem(ppd,y)
end
hold off
end