load txt file in matrix into matlab

3 ビュー (過去 30 日間)
polo Mahmoud
polo Mahmoud 2020 年 6 月 2 日
回答済み: Ameer Hamza 2020 年 6 月 2 日
how to load this into matlab from a txt file:
[1 2 1 E A Iy Iz Ix J
2 3 2 E A Iy Iz Ix J
3 4 3 E A Iy Iz Ix J]
the problem is that the letters E A Iy Iz Ix J ----> gives NaN when I load it into matlab
  6 件のコメント
madhan ravi
madhan ravi 2020 年 6 月 2 日
Rik probably he would need the letters for his symbolic computations. So the solution is to use textscan(...) as KSSV suggested.
polo Mahmoud
polo Mahmoud 2020 年 6 月 2 日
i need the numbers and letters as the letters later in matlab has to replaced by numbers

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

採用された回答

Anish Walia
Anish Walia 2020 年 6 月 2 日
Since the data type of all values is not same, try importing it as cell array
data = readcell('testload.txt')
  1 件のコメント
polo Mahmoud
polo Mahmoud 2020 年 6 月 2 日
Thank

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

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 6 月 2 日
As Madhan mentioned that you might want to load it as symbolic, you may try
str = fileread('test.txt');
words = regexp(str, '\w+', 'match');
idx = cellfun(@(x) isnan(str2double(x)), words);
syms(words(idx));
M = eval(str);

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by