Removing first row from txt file

5 Ansichten (letzte 30 Tage)
Stephen Warren
Stephen Warren am 11 Jun. 2020
Kommentiert: Atsushi Ueno am 11 Jun. 2020
Hi everyone,
I have a very simple text file with 2 columns of data I wish to plot. I'm having trouble removing the first row which contains non-number values.
Data example:
txtcol1, txtcol2
4, 107
4, 109
5, 110
5, 111
5, 112
This is what I have so far: (..% to my understanding)
data=('myfile.txt'); %sets variable
readtable(data) $%displays table
data(1,:) = 0; %sets first row to zeros
x = data(:,1); %sets x to column 1
y = data(:,2); %sets y to column 2
plot(x, y) %plots
I'm getting this returned:
Error using plot
Invalid first data argument.
Thank you very much
  2 Kommentare
madhan ravi
madhan ravi am 11 Jun. 2020
Attach file
Atsushi Ueno
Atsushi Ueno am 11 Jun. 2020
I have created 'myfile.txt' file with assamption.
>> read_data = readtable('myfile.txt')
read_data =
3×2 table
abc def
___ ___
3 5
4 9
3 8
readtable() returens output as a table. The table can store metadata such as descriptions, variable units, variable names, and row names. How about using the first row's information you are trying to remove...
data = readtable('myfile.txt') %displays data as table
x = data.abc; % set x to first column of myfile.txt
y = data.def; % set y to second column of myfile.txt
plot(x, y) % plot

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 11 Jun. 2020
data=('myfile.txt'); %sets variable
data = readtable(data) %displays table
x = data{:,1}; %sets x to column 1
y = data{:,2}; %sets y to column 2
plot(x, y) %plots
  1 Kommentar
Stephen Warren
Stephen Warren am 11 Jun. 2020
Thank you very much,
I see my error was not using {} for the matrix

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by