How to import data from .txt file?

345 vues (au cours des 30 derniers jours)
Benjamin Watson
Benjamin Watson le 13 Avr 2016
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

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 13 Avr 2016
Modifié(e) : Azzi Abdelmalek le 13 Avr 2016
Spill1 = importdata('Spill.txt');
Spill=Spill1.data
T = Spill(:,1);
C = Spill(:,2);
plot(T,C)
xlabel('Time / Days');
ylabel('Concentration / ppb')

Plus de réponses (2)

ghozy shalahuddin
ghozy shalahuddin le 10 Oct 2019
vh

parham kianian
parham kianian le 2 Sep 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:
  1 commentaire
Jan Babiuch-Hall
Jan Babiuch-Hall le 3 Mai 2022
Video unavailale :(

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by