How can I read text file data separately row by row into different array
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, everyone. If the text tile data is shown as below:
13,7,8,4,9
3,21,5,3,7
4,6,87,35,7
45,2,5
I would like to read the text file into different array like a=[13 7 8 4 9], b=[3 21 5 3 7;4 6 87 35 7] and c=[45 2 5]. Is there any code to solve this problem? Thank you for reading my question.
0 comentarios
Respuestas (1)
Srivardhan Gadila
el 11 de Abr. de 2020
Editada: Srivardhan Gadila
el 11 de Abr. de 2020
The following code might help you:
filename = 'textFile.txt';
delimiterIn = '\n';
Data = importdata(filename,delimiterIn);
a = str2num(Data{1})
b = [str2num(Data{2});str2num(Data{3})]
c = str2num(Data{4})
Or
filename = 'textFile.txt';
delimiterIn = ',';
Data = importdata(filename,delimiterIn);
a = Data(1,:)
b = Data(2:3,:)
c = Data(4,:)
c = c(~isnan(c))
The textFile.txt has the following data:
13,7,8,4,9
3,21,5,3,7
4,6,87,35,7
45,2,5
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!