How to read a text file and construct a matrix

2 ビュー (過去 30 日間)
Dimitrios Anagnostakis
Dimitrios Anagnostakis 2016 年 11 月 17 日
編集済み: Walter Roberson 2016 年 11 月 17 日
Hi all,
I'd like to ask your help for a task I need to do.
I'm trying to read a text file with format as in the picture
and then create a matrix with 4 columns like the following
Please any advice-suggestion would be very welcome.
Cheers,
Dimi
  3 件のコメント
Dimitrios Anagnostakis
Dimitrios Anagnostakis 2016 年 11 月 17 日
At the moment, I'm getting the contents to an array. I'm using this code.
fileID = fopen('example.txt');
formatSpec = '%s %s %s %s';
C = textscan(fileID,formatSpec,...
'Delimiter', '\n', ...
'Delimiter', '\n', ...
'CollectOutput', true)
fclose(fileID);
The result is in the picture below.
I'd like to get the second column into two different ones in order to have the 4 columns matrix.
Any ideas?
Cheers Dimi
Dimitrios Anagnostakis
Dimitrios Anagnostakis 2016 年 11 月 17 日
編集済み: Dimitrios Anagnostakis 2016 年 11 月 17 日
Well, I managed to get the second column separated as shown below.
Now I need to convert these to matrices in order to perform some calculations. I tried the cell2mat, but although it doesn't return any error message, it doesn't look like to be working.
Any suggestions?
Thanks, Dimi

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by