古詩詞大全網 - 古詩大全 - 請問如何用MATLAB讀入TXT中帶逗號的矩陣,比如txt中是“1,2,3,4,5” 如何讀入matlab使其變為5*1的矩陣

請問如何用MATLAB讀入TXT中帶逗號的矩陣,比如txt中是“1,2,3,4,5” 如何讀入matlab使其變為5*1的矩陣

用textread,matlab內置幫助中例子如下

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);