import a text file into a variable

Hello,
I have the attached text file and I want to import it and put it into a matrix variable
what is the simplest function to do the work?

2 comentarios

Cedric
Cedric el 17 de Sept. de 2017
What have you tried so far?
Ahmed Nabil
Ahmed Nabil el 18 de Sept. de 2017
I tried to use this function but didn't work
https://www.mathworks.com/help/matlab/ref/readtable.html

Iniciar sesión para comentar.

 Respuesta aceptada

KSSV
KSSV el 18 de Sept. de 2017

1 voto

doc load, importdata.

Más respuestas (3)

Guillaume
Guillaume el 18 de Sept. de 2017
Editada: Guillaume el 18 de Sept. de 2017
I tried to use this function but didn't work.
Utterly useless statement.
>> t = readtable('Uz.txt', 'ReadVariableNames', false);
>> summary(t)
Variables:
Var1: 109×1 double
Values:
Min 3.9152
Median 6.5121
Max 11.463
Clearly works.
If "it didn't work" then you need to provide the exact code you've used and the exact error code you get otherwise we have no idea why "it didn't work".
KL
KL el 18 de Sept. de 2017
data = readtable('Uz.txt');
or for just one column,
data = textread('Uz.txt')
Jan
Jan el 18 de Sept. de 2017
What exactly is "simple"?
fid = fopen(FileName, 'r');
if fid == -1
error('Cannot open file: %s', FileName);
end
Data = fscanf(fid, '%g', inf);
fclose(fid);
Here "simple" means, that reading the documentation of the commands can be done quickly. textscan might look easier in the code, but you have much more options and reading the docs needs more time in consequence.

Etiquetas

Preguntada:

el 17 de Sept. de 2017

Comentada:

el 25 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by