フィルターのクリア

How to save data from a txt file into a matrix?

4 ビュー (過去 30 日間)
Sahar Sowdagar
Sahar Sowdagar 2020 年 11 月 11 日
編集済み: Ameer Hamza 2020 年 11 月 11 日
I have a txt file that looks something like this:
>01 01 2020
A 1 2 3
B 4 5 6
C 8 9 0
>02 01 2020
A 3 4 5
B 7 6 5
C 5 7 6
I need matlab to read the file, and then make a matrix for the date (after the >) and the data in each date (a col for A, B, C)
i read the file using fopen, and i set line=fgetl(txtfile) but im not sure how to make it read a new row in the matric everytime there is a '>', or place the value of specific columns in the txt file in a column in the matrix.
Im sorry if this question is very stupid, i just started working with matlab and im facing a lot of difficulties.
  1 件のコメント
Rik
Rik 2020 年 11 月 11 日
It sounds like you need a loop. Inside that loop you can check if the first character is < and increment a row counter.

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 11 日
編集済み: Ameer Hamza 2020 年 11 月 11 日
Try this
f = fopen('data.txt');
data = textscan(f, '%c%f%f%f\n');
fclose(f);
data = [data{2:end}];
data.txt is attached.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by