load txt file in matrix into matlab

2 views (last 30 days)
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
polo Mahmoud
polo Mahmoud on 2 Jun 2020
i need the numbers and letters as the letters later in matlab has to replaced by numbers

Sign in to comment.

Accepted Answer

Anish Walia
Anish Walia on 2 Jun 2020
Since the data type of all values is not same, try importing it as cell array
data = readcell('testload.txt')

More Answers (1)

Ameer Hamza
Ameer Hamza on 2 Jun 2020
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);
M = eval(str);


Find more on Data Import and Export in Help Center and File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by