MATLAB CREATES AN EXTRA COLUMN WHILE READING A TXT FILE

Hello ,
I have a txt file which i have attached and it have 4 columns. When i read it with matlab it creates an extra column with zeros so it is like that :
2 1 1 0 0
1 1 1 0 0
and the txt file is this
2 1 1 0
1 1 1 0
i use this command to open the txt file
n_values = textread('n_values.txt');
can anyone help me ?

2 件のコメント

Walter Roberson
Walter Roberson 2020 年 9 月 7 日
Which MATLAB release are you using, and which operating system? I am not seeing that on R2020a on Mac.
I note that your file has both carriage return and line feed, so it is most likely to have been created on Windows.
chntua chntua
chntua chntua 2020 年 9 月 7 日
i use R2018b and windows 10

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

 採用された回答

VBBV
VBBV 2020 年 9 月 7 日
編集済み: Walter Roberson 2020 年 9 月 8 日

0 投票

Try load function instead As below
values = load('n_values.txt');
You are also using same variable name as the filename. Use a different variable name after importing data as shown above

2 件のコメント

chntua chntua
chntua chntua 2020 年 9 月 7 日
ok thanks a lot ! it works !
Walter Roberson
Walter Roberson 2020 年 9 月 8 日
There is no need to use a different variable name than the file name. The file name is a character vector, and whether you use a variable with the same name or not is not going to affect your code (provided that whatever name you use does not conflict with anything else.)

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

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 9 月 7 日

編集済み:

2020 年 9 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by