%功能:显示散点图
%说明:在以下Matlab入门程序中,最值得注意的是函数的定义和调用。
1.test.m
%Initialization
clear;close all;clc
fprintf('Plotting Data ...\n')
% load "ex1data1.txt" into data
data = load('ex1data1.txt');
% X is the first colunm in data
% y is the second colunm in data
X = data(:, 1); y = data(:, 2);
%number of training examples
m = length(y);
% Plot Data
% Note: You have to complete the code in plotData.m
plotData(X, y);
fprintf('Program paused. Press enter to continue.\n');
pause;
2.ex1data1.txt
8.2342,18.352
2.375,12.352
4.284,15.258
3.plotData.m
function plotData(x,y)
%myFun - Description
%
% Long description
figure
plot(x,y,'Color','g','LineStyle','none','Marker','x','MarkerSize',10);
title('plotData');
xlabel('Population of City in 10,000s');
ylabel('Profit in $10,000s');
end
4.图