第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

'\n'怎么放?放到哪才有換行作用?謝謝

'\n'怎么放?放到哪才有換行作用?謝謝

[c1 c2 c3 c4] = textread('sample_file2.txt','%s %s %s %s','headerlines',2),其中的headerlines是什么意思?還有,file = textread('fft.m','%s','delimiter','\n','whitespace','');其中的delimiter,whitespace有什么作用?
查看完整描述

2 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

headerlines表示開頭跳過幾行(有的文件開頭有說明文字)
delimiter 設(shè)置分隔符,用來(lái)隔開多個(gè)數(shù)據(jù),whitespace表示把這個(gè)字符作為空格來(lái)處理 區(qū)別是分隔符更嚴(yán)格,只要讀到這個(gè)字符,當(dāng)前的這個(gè)數(shù)據(jù)就截止了,空格則不一定,具體情況自己試驗(yàn)一下了

help里說的很詳細(xì),懂英文的話自己看下
textread

Read data from text file; write to multiple outputs

Note textread is not recommended. Use textscan to read data from a text file.

Graphical Interface

As an alternative to textread, use the Import Wizard. To activate the Import Wizard, select Import Data from the File menu.
Syntax

[A,B,C,...] = textread('filename','format')
[A,B,C,...] = textread('filename','format',N)
[...] = textread(...,'param','value',...)
Description

[A,B,C,...] = textread('filename','format') reads data from the file 'filename' into the variables A,B,C, and so on, using the specified format, until the entire file is read. The filename and format inputs are strings, each enclosed in single quotes. textread is useful for reading text files with a known format. textread handles both fixed and free format files.

Note When reading large text files, reading from a specific point in a file, or reading file data into a cell array rather than multiple outputs, you might prefer to use the textscan function.

textread matches and converts groups of characters from the input. Each input field is defined as a string of non-white-space characters that extends to the next white-space or delimiter character, or to the maximum field width. Repeated delimiter characters are significant, while repeated white-space characters are treated as one.

The format string determines the number and types of return arguments. The number of return arguments is the number of items in the format string. The format string supports a subset of the conversion specifiers and conventions of the C language fscanf routine. Values for the format string are listed in the table below. White-space characters in the format string are ignored.

format

Action

Output

Literals

(ordinary characters)

Ignore the matching characters. For example, in a file that has Dept followed by a number (for department number), to skip the Dept and read only the number, use 'Dept' in the format string.

None
%d 

Read a signed integer value.

Double array
%u 

Read an integer value.

Double array
%f 

Read a floating-point value.

Double array
%s 

Read a white-space or delimiter-separated string.

Cell array of strings
%q 

Read a double quoted string, ignoring the quotes.

Cell array of strings
%c 

Read characters, including white space.

Character array
%[...] 

Read the longest string containing characters specified in the brackets.

Cell array of strings
%[^...] 

Read the longest nonempty string containing characters that are not specified in the brackets.

Cell array of strings
%*...
instead of % 

Ignore the matching characters specified by *.

No output
%w...
instead of % 

Read field width specified by w. The %f format supports %w.pf, where w is the field width and p is the precision.

[A,B,C,...] = textread('filename','format',N) reads the data, reusing the format string N times, where N is an integer greater than zero. If N is smaller than zero, textread reads the entire file.

[...] = textread(...,'param','value',...) customizes textread using param/value pairs, as listed in the table below.

param

value

Action
bufsize 

Positive integer

Specifies the maximum string length, in bytes. Default is 4095.
commentstyle matlab 

Ignores characters after %.
commentstyle shell 

Ignores characters after #.
commentstyle c 

Ignores characters between /* and */.
commentstyle c++ 

Ignores characters after //.
delimiter 

One or more characters

Act as delimiters between elements. Default is none.
emptyvalue 

Scalar double

Value given to empty cells when reading delimited files. Default is 0.
endofline 

Single character or '\r\n'

Character that denotes the end of a line.

Default is determined from file
expchars 

Exponent characters

Default is eEdD.
headerlines 

Positive integer

Ignores the specified number of lines at the beginning of the file.
whitespace 

Any from the list below:

Treats vector of characters as white space. Default is ' \b\t'.
' '
\b
\n
\r
\t 

Space
Backspace
Newline
Carriage return
Horizontal tab

Note When textread reads a consecutive series of whitespace values, it treats them as one white space. When it reads a consecutive series of delimiter values, it treats each as a separate delimiter.

Remarks

If you want to preserve leading and trailing spaces in a string, use the whitespace parameter as shown here:

textread('myfile.txt', '%s', 'whitespace', '')
ans = 
' An example of preserving spaces '

Examples
Example 1 — Read All Fields in Free Format File Using %

The first line of mydata.dat is

Sally Level1 12.34 45 Yes

Read the first line of the file as a free format file using the % format.

[names, types, x, y, answer] = textread('mydata.dat', ...
'%s %s %f %d %s', 1)

returns

names = 
'Sally'
types = 
'Level1'
x =
12.34000000000000
y =
45
answer = 
'Yes'

Example 2 — Read as Fixed Format File, Ignoring the Floating Point Value

The first line of mydata.dat is

Sally Level1 12.34 45 Yes

Read the first line of the file as a fixed format file, ignoring the floating-point value.

[names, types, y, answer] = textread('mydata.dat', ...
'%9c %5s %*f %2d %3s', 1)

returns

names =
Sally  
types = 
'Level1'
y =
45
answer = 
'Yes'

%*f in the format string causes textread to ignore the floating point value, in this case, 12.34.
Example 3 — Read Using Literal to Ignore Matching Characters

The first line of mydata.dat is

Sally Type1 12.34 45 Yes

Read the first line of the file, ignoring the characters Type in the second field.

[names, typenum, x, y, answer] = textread('mydata.dat', ...
'%s Type%d %f %d %s', 1)

returns

names = 
'Sally'
typenum =
1
x =
12.34000000000000
y =
45
answer = 
'Yes'

Type%d in the format string causes the characters Type in the second field to be ignored, while the rest of the second field is read as a signed integer, in this case, 1.
Example 4 — Specify Value to Fill Empty Cells

For files with empty cells, use the emptyvalue parameter. Suppose the file data.csv contains:

1,2,3,4,,6
7,8,9,,11,12

Read the file using NaN to fill any empty cells:

data = textread('data.csv', '', 'delimiter', ',', ... 
'emptyvalue', NaN);

Example 5 — Read M-File into a Cell Array of Strings

Read the file fft.m into cell array of strings.

file = textread('fft.m', '%s', 'delimiter', '\n', ...
'whitespace', '');

 


查看完整回答
反對(duì) 回復(fù) 2023-04-25
?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

一些低級(jí)的I/O處理及相關(guān)介紹
函數(shù) 功能
fclose 關(guān)閉打開的文件
feof 判斷是否為文件結(jié)尾
ferror 文件輸入輸出中的錯(cuò)誤查找
fgetl 讀入一行,忽略換行符
fgets 讀入一行,直到換行符
fopen 打開文件,或者獲取打開文件的信息
fprintf 格式化輸入數(shù)據(jù)到文件
fread 從文件中讀取二進(jìn)制數(shù)據(jù)
frewind 將文件的位置指針移至文件開頭位置
fscanf 格式化讀入
fseek 設(shè)置文件位置指針
ftell 文件位置指針
fwrite 向文件中寫入數(shù)據(jù)

下面重點(diǎn)介紹函數(shù)fprintf。該函數(shù)的調(diào)用格式如下:
count=fprintf(fid,format,A,...),該語(yǔ)句將矩陣A及后面其他參數(shù)中數(shù)字的實(shí)部以format指定的格式寫入到fid指定的文件中,返回寫入數(shù)據(jù)的字節(jié)數(shù)。
上面語(yǔ)句中,參數(shù)format由%開頭,共可由4個(gè)部分組成,分別如下:
●標(biāo)記(flag),為可選部分。
●寬度和精度指示,為可選部分。
●類型標(biāo)志符,為可選部分。
●轉(zhuǎn)換字符,為必需部分。

1.標(biāo)記
標(biāo)記用于控制輸出的對(duì)齊方式,可以選擇的內(nèi)容如下
函數(shù) 功能 示例  
負(fù)號(hào)(-) 在參數(shù)左側(cè)進(jìn)行判別 %-5.2 d
加號(hào)(+) 在數(shù)字前添加符號(hào) %+5.2 d
空格 在數(shù)字前插入空格 %5.2 d
0 在數(shù)字前插入0 %0 5.2 d

2.寬度和精度指示
用戶可以通過數(shù)字指定輸出數(shù)字的寬度及精度,格式如下:
●o,指定數(shù)字的寬度;
●%6.2f,指定數(shù)字的寬度及精度;
●%.2f,指定數(shù)字的精度。

3.轉(zhuǎn)換字符
轉(zhuǎn)換字符用于指定輸出的符號(hào),可以選擇的內(nèi)容如下
標(biāo)志符 意義
%c 輸出單個(gè)字符
%d 輸出有符號(hào)十進(jìn)制數(shù)
%e 采用指數(shù)格式輸出,采用小寫字母e,如:3.1415e+00
%E 采用指數(shù)格式輸出,采用大寫字母E,如:3.1415E+00
%f 以定點(diǎn)數(shù)的格式輸出
%g %e及%f 更緊湊的格式,不顯示數(shù)字中無(wú)效的0
%G與%g相同,但是使用大寫字母E
%i 有符號(hào)十進(jìn)制數(shù)
%o 無(wú)符號(hào)八進(jìn)制數(shù)
%s 輸出字符串
%u 無(wú)符號(hào)十進(jìn)制數(shù)
%x 十六進(jìn)制數(shù)(使用小寫字母a-f)
%X 十六進(jìn)制數(shù)(使用大寫字母A-F)
其中%o、%u、%x、%X支持使用子類型。

例如:
例13-7 fprintf格式化輸出示例。
>>x=0:.1:1;
>>y=[x;exp(x)];
>>fid=fopen('exp.txt','wt');
>>fprintf(fid,'%6.2f.8f\n',y);
>>fclose(fid)
ans=
0
顯示該文件:
>>typeexp.txt
0.00 1.00000000
0.10 1.10517092

0.90 2.45960311
1.00 2.71828183

f p r i n t f(1,'It''s Friday.\n')
It's Friday. 在該例中,利用1表示顯示器,并且用兩個(gè)單引號(hào)顯示單引號(hào),使用\n進(jìn)行換行。在格式化輸出中,這類符號(hào)稱為轉(zhuǎn)義符。MATLAB中的常用轉(zhuǎn)義符如表下所示。

轉(zhuǎn)義符 功能
\b 退格
\f 表格填充
\n 換行符
\r 回車
\t t a b
\\ \,反斜線
\''或'' ',單引號(hào)
%% %,百分號(hào)


查看完整回答
反對(duì) 回復(fù) 2023-04-25
  • 2 回答
  • 0 關(guān)注
  • 242 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)