www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ImportCommaSeparatedDataExample.m
%% Import Comma-Separated Data % This example shows how to import comma-separated numeric data from a text % file, using the |csvread| function. %% % Create a sample file named |ph.dat| that contains the following % comma-separated data: % % 85.5, 54.0, 74.7, 34.2 % 63.0, 75.6, 46.8, 80.1 % 85.5, 39.6, 2.7, 38.7 % % Copyright 2015 The MathWorks, Inc. A = 0.9*gallery('integerdata',99,[3,4],1); dlmwrite('ph.dat',A,',') %% % The sample file, |ph.dat|, resides in your current folder. %% % Read the entire file using |csvread|. The file name is the only required % input argument to the |csvread| function. M = csvread('ph.dat') %% % |M| is a 3-by-4 |double| array containing the data from the file. %% % Import only the rectangular portion of data starting from the first row % and third column in the file. When using |csvread|, row and column % indices are zero-based. N = csvread('ph.dat',0,2)