How to import data from .txt file?

363 次查看(过去 30 天)
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-4-13
编辑:Azzi Abdelmalek 2016-4-13
Spill1 = importdata('Spill.txt');
Spill=Spill1.data
T = Spill(:,1);
C = Spill(:,2);
plot(T,C)
xlabel('Time / Days');
ylabel('Concentration / ppb')

更多回答(2 个)

ghozy shalahuddin
ghozy shalahuddin 2019-10-10
vh

parham kianian
parham kianian 2020-9-2
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:

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by