matlab contour光滑,Matlab contour作图不显示的可能原因
復(fù)習(xí)Coursera上斯坦福Andrew Ng的Machine Learning課程,做到week 7的ex6時(shí),發(fā)現(xiàn)ex6.m后兩個(gè)作圖出不來(lái)。
ex6.m有三次作圖:一次是直線邊界,兩次曲線。這里顯示不出的是后兩個(gè),本該顯示藍(lán)色邊界的地方空白。而之前做題時(shí)正常可用。
其他版本的matlab運(yùn)行正常,可能是因?yàn)镸atlab新版本中個(gè)別函數(shù)有變動(dòng)。問(wèn)題應(yīng)該就出在作圖函數(shù)visualizeBoundary.m這里。
該函數(shù)代碼如下:
function visualizeBoundary(X, y, model, varargin)
%VISUALIZEBOUNDARY plots a non-linear decision boundary learned by the SVM
% VISUALIZEBOUNDARYLINEAR(X, y, model) plots a non-linear decision
% boundary learned by the SVM and overlays the data on it
% Plot the training data on top of the boundary
plotData(X, y)
% Make classification predictions over a grid of values
x1plot = linspace(min(X(:,1)), max(X(:,1)), 100)';
x2plot = linspace(min(X(:,2)), max(X(:,2)), 100)';
[X1, X2] = meshgrid(x1plot, x2plot);
vals = zeros(size(X1));
for i = 1:size(X1, 2)
this_X = [X1(:, i), X2(:, i)];
vals(:, i) = svmPredict(model, this_X);
end
% Plot the SVM boundary
hold on
contour(X1, X2, vals, [0 0], 'Color', 'b');
% % When running the original-version codes downloaded from Coursera,
% % if the boundary doesn't show up, try another parametre like [0.5,0.5]
% % instead of [0 0].
% % It seems there're certain shifts of the plot function
% % in some newer versions of Matlab where [0 0] means "no width".
hold off;
end
問(wèn)題顯然就在contour上。中間的[0 0]參數(shù)之前沒(méi)用過(guò),修改了一下,改成[0.5 0.5],作圖就正常了。可能是邊界線型屬性。
% %行注釋是我加的。
這次的問(wèn)題可能是因?yàn)镸atlab新版本中個(gè)別函數(shù)有變動(dòng),另一個(gè)體現(xiàn)是上述圖形的邊界直接卡到了輸入數(shù)據(jù)上,而沒(méi)有留下一定空間。這一點(diǎn)跟之前也不太一樣。
總結(jié)
以上是生活随笔為你收集整理的matlab contour光滑,Matlab contour作图不显示的可能原因的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql 指示符安装,Mysql的安装
- 下一篇: php中文网企业网站,闻名 PHP企业网