Why doesn't importdata recognize space or tab as delimiters?

I am working on MATLAB 2015a and trying to process a data matrix which looks like this.
Each number is separated by a tab. However, when I tried to import my data using
data = importdata('myfile.txt');
the result is not a multi-row numerical matrix, but a single-row char matrix. I tried to switch the delimiter to space, but it doesn't work. I even specified the delimiter using
[data, delim] = importdata('myfile.txt', '\t');
or
[data, delim] = importdata('myfile.txt', ' ');
but it still doesn't work and the returned delim is NaN. How can I solve this problem? Thank you!

 Respuesta aceptada

madhan ravi
madhan ravi el 10 de Oct. de 2018
Editada: madhan ravi el 10 de Oct. de 2018
fid =fopen('myfile.txt','r')
file = textscan(fid,'%f %f %f %f %f %f %f %f %f %f %f \n','Delimiter','','collectoutput',1);
fclose(fid)
cell2mat(file)
or try
a=load('myfile.txt')
data = importdata('myfile.txt') %couldn't regenerate the issue in 2017a

4 comentarios

if it works accept my answer if not let know what's additionally required
Using the load command works. Thanks!
you're welcome
Damian
Damian el 21 de Oct. de 2022
Editada: Damian el 21 de Oct. de 2022
data = importdata('myfile.txt', ' ');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

el 10 de Oct. de 2018

Editada:

el 21 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by