Separating a colymn into two columns (.txt file)

3 ビュー (過去 30 日間)
Ivan Mich
Ivan Mich 2019 年 9 月 24 日
コメント済み: David K. 2019 年 10 月 1 日
Hello,
I would like to separate a column into two different columns from a .txt file in Matlab. I used these commands:
t=readtable('file.txt','Delimiter','\t','HeaderLines',1)
and the results of these commands are in the pictures. Finally, I mean that i would like to separate line 11 into two vertical columns.
Which command should I use?

採用された回答

David K.
David K. 2019 年 9 月 24 日
編集済み: David K. 2019 年 9 月 24 日
I would do it like this:
%t = your table;
dataCell = table2cell(t); % convert to cells
dataCell = dataCell(11:end); % remove unneccessary text
cellNums = cellfun(@str2num,dataCell,'UniformOutput',0); % apply str to num on all the data
output = cell2mat(cellNums); % convert to matrix with 2 columns
*Edit: fixed a few things
  10 件のコメント
Ivan Mich
Ivan Mich 2019 年 10 月 1 日
Ok, one last question please. If i would want to "pick" from this .txt file (see image up) only the number of 9th line which command would help me to make it?
David K.
David K. 2019 年 10 月 1 日
Personally, I'm not great at reading in and out files all that well. I think there are some commands that let you set where you are reading in from and how how much to read in. But since the matrix is all ready read into matlab I would just use the matrix index to choose the value you need.
If you really only want to get one value then I would check out fseek and other f- commands.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by