How to import data from .txt file?

503 visualizaciones (últimos 30 días)
Benjamin Watson
Benjamin Watson el 13 de Abr. de 2016
Comentada: Jan Babiuch-Hall el 3 de Mayo de 2022
Hi All,
Ive tried importing my data via this code;
Spill = importdata('Spill.txt');
T = Spill(:,1);
C = Spill(:,2);
plot(T,C)
xlabel('Time / Days');
ylabel('Concentration / ppb')
but it doesn't work as it says "Index exceeds matrix dimensions.". It needs to be inputted by code and not just the import button. Can someone help? Ive attached the .txt file

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Abr. de 2016
Editada: Azzi Abdelmalek el 13 de Abr. de 2016
Spill1 = importdata('Spill.txt');
Spill=Spill1.data
T = Spill(:,1);
C = Spill(:,2);
plot(T,C)
xlabel('Time / Days');
ylabel('Concentration / ppb')

Más respuestas (2)

ghozy shalahuddin
ghozy shalahuddin el 10 de Oct. de 2019
vh

parham kianian
parham kianian el 2 de Sept. de 2020
I think it is much easier to use textread function. Following link describe in full detail how to use this function to import data from a text file:

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by