How to load data from and .txt file?

97 ビュー (過去 30 日間)
Benjamin Watson
Benjamin Watson 2016 年 4 月 15 日
回答済み: parham kianian 2020 年 9 月 2 日
Hi All,
Ive been trying to load data from the .txt file that I've attached. What I've got so far is:
Spill = importdata('Spill.txt');
T = Spill(:,1);
C = Spill(:,2);
but I get an error "Index exceeds Matrix Dimensions". Can some please help me out. I can't change to ".data" file either as I have to extract the columns of data directly out of the .txt file. Much appreciated in advance.

回答 (2 件)

J. Webster
J. Webster 2016 年 4 月 15 日
編集済み: J. Webster 2016 年 4 月 15 日
To read a tab delimited ascii file while skipping the first row, try:
data = dlmread('Spill.txt','\t',1,0);
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 4 月 15 日
fid = fopen('Spill.txt', 'rt');
data = cell2mat( textscan(fid, '%f%f', 'Delimiter', '\t', 'HeaderLines', 1) );
fclose(fid)

サインインしてコメントする。


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:

Community Treasure Hunt

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

Start Hunting!

Translated by