matrix with characters and numbers from text file

19 ビュー (過去 30 日間)
polo Mahmoud
polo Mahmoud 2019 年 11 月 1 日
コメント済み: polo Mahmoud 2019 年 11 月 4 日
Hi, if I have a txt. file with 2 different matrix in the text. file and i want them to be read into matlab, eg:
this is from the txt. file:
% A =
[ 1 2 3 E
5 6 7 E]
% B =
[9 10 11 IX
13 14 15 IX]
and i want matlab to know the diffrent between these two element when it reads the file. so i can make them longer or shorter and it should still be able to take both matrix our with the characters and numbers
  4 件のコメント
Bhaskar R
Bhaskar R 2019 年 11 月 1 日
編集済み: Bhaskar R 2019 年 11 月 1 日
It seems all matrices are extracted from the text file except last matrix
% connec
[1 2 1 2e11 A Ix
2 3 2 2e11 A Ix
3 4 3 2e11 A Ix
4 5 4 2e11 A Ix
5 6 5 2e11 A Ix];
It contained numerical with character data thats why it unable to perform
AAA = cell2mat(parts_value);
hence further statements you can't execute
In the cell variable parts_value you can get the all matrices correctly except last matrix as
parts_value{1}, parts_value{2}..parts_value{6}
polo Mahmoud
polo Mahmoud 2019 年 11 月 1 日
編集済み: polo Mahmoud 2019 年 11 月 1 日
so i cant get the last matrix out anyway Bhaskar R ?

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

回答 (1 件)

Mil Shastri
Mil Shastri 2019 年 11 月 1 日
You could use the import tool and even provide the url of the txt file (https://www.mathworks.com/matlabcentral/answers/uploaded_files/246014/coord2.txt)
You could then set the output type as a table/cell array/ whatever you like and then generate a script for it. You will notice that it eventually uses readtable with some options (not shown below)
% Import the data
coord21 = readtable("coord2.txt", opts);
  1 件のコメント
polo Mahmoud
polo Mahmoud 2019 年 11 月 4 日
it does not work for me, it says in the table NaN to all the "letters", but it can load the numbers.

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

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by