How to load and read these files in matlab?

21 ビュー (過去 30 日間)
SUNANNA S S
SUNANNA S S 2017 年 4 月 20 日
コメント済み: SUNANNA S S 2017 年 4 月 20 日
Please help me to load and read this file and convert it to corresponding adjacency matrix.

採用された回答

Philip G
Philip G 2017 年 4 月 20 日
編集済み: Philip G 2017 年 4 月 20 日
If you are unsure how to import a certain file ... you can use the import wizard (right click on your file in MATLAB and choose "import data"). Then adjust the settings how you want to import the data and finally on the right side under "import selection" choose "generate script".
For the first file (retweet.txt) - this is a code that should work (which basically has just been copied from the "generate script" result):
%%Initialize variables.
filename = 'retweet.txt';
delimiter = ',';
%%Read columns of data as text:
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%[^\n\r]';
%%Open the text file.
fileID = fopen(filename,'r');
%%Read columns of data according to the format.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);
%%Close the text file.
fclose(fileID);
For the second file - change the following:
delimiter = '\t';
formatSpec = '%s%s%s%[^\n\r]';
You just have to convert the resulting cell arrays into the type of your choosing. Also here - the "generate script" button creates these lines for you (and will follow the lines I pasted in the beginning).
  1 件のコメント
SUNANNA S S
SUNANNA S S 2017 年 4 月 20 日
Thank you Sir

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by