How to import data from .txt file?

조회 수: 69 (최근 30일)
Benjamin Watson
Benjamin Watson 2016년 4월 13일
댓글: Jan Babiuch-Hall 2022년 5월 3일
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