% Plot Data 散点图:程序实现绘制一个一X,y为数据,红色的x作为标记的散点图,标记大小为10,并加入横纵坐标轴的题目
plot(X, y, 'rx', 'MarkerSize', 10); % Plot the data
ylabel('Profit in $10,000s'); % Set the y?axis label
xlabel('Population of City in 10,000s'); % Set the x?axis label
--------------------------------------
% Surface plot 表面图:程序以theta0_vals、theta1_vals为两个变量,J_vals为结果绘制表面图。注:theta0_vals、theta1_vals各为1*100的行向量,J_vals为100*100的方阵
figure;
surf(theta0_vals, theta1_vals,J_vals)
xlabel('\theta_0'); ylabel('\theta_1');
-------------------------------------------------------
% Contour plot 轮廓图,contour(x,y,z,v):其中x,y为横纵坐标,z为等高线值的大小,同样x为100*1,y为100*1,z为100*100;同时v向量规定了等高线的范围为(通过logspace函数取到10^-2 → 10^3,取20个值)
figure;
% Plot J_vals as 15contours spaced logarithmically between 0.01 and 100
contour(theta0_vals,theta1_vals, J_vals, logspace(-2, 3, 20))
xlabel('\theta_0'); ylabel('\theta_1');
hold on;
plot(theta(1), theta(2), 'rx', 'MarkerSize', 10, 'LineWidth', 2);
-------------------------------------------------------