www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReadAStringExample.m
%% Read Floating-Point Numbers %% % Read a character vector containing floating-point numbers. chr = '0.41 8.24 3.57 6.24 9.27'; C = textscan(chr,'%f'); %% % The specifier |'%f'| in |formatSpec| tells |textscan| to % match each field in |chr| to a double-precision floating-point number. %% % Display the contents of cell array |C|. celldisp(C) %% % Read the same character vector, and truncate each value to one decimal % digit. C = textscan(chr,'%3.1f %*1d'); %% % The specifier |%3.1f| indicates a field width of 3 digits and a precision % of 1. The |textscan| function reads a total of 3 digits, including the decimal point % and the 1 digit after the decimal point. The specifier, |%*1d|, tells % |textscan| to skip the remaining digit. %% % Display the contents of cell array |C|. celldisp(C)