How to read the data from .txt file and plot?

434 ビュー (過去 30 日間)
muhammad choudhry
muhammad choudhry 2021 年 6 月 17 日
編集済み: muhammad choudhry 2021 年 6 月 17 日
Hi,
I am extracting data from one of the sensors, and data is coming out in the .txt file where I am reading the data using the code below but I am struggling to plot the data (usually I use the excel file and just simply plot from there), I am attaching the file if some one can help. Basically I want to plot time on x-axis and all the other columns (0,7) on y axis individually or all on one graph as well.
Code:
data = readtable ('rans1_dynamicpoints.txt');
T = data(:,1);
T2 = data(:,2);
plot (T,T2,'x');
Error:
Error using tabular/plot (line 217)
Tables and timetables do not have a plot method. To plot a table or a timetable, use the stackedplot function. As an alternative,
extract table or timetable variables using dot or brace subscripting, and then pass the variables as input arguments to the plot
function.
Error in txt_csv (line 7)
plot (T,T2,'x');

採用された回答

Stephen23
Stephen23 2021 年 6 月 17 日
編集済み: Stephen23 2021 年 6 月 17 日
Read the error message and follow its advice to use curly-brace subscripting rather than parentheses:
data = readtable('rans1_dynamicpoints.txt');
T = data{:,1};
T2 = data{:,2};
plot (T,T2,'x');
Is there a particular reason why you need to use a table? Would a simple numeric matrix suffice?:
data = readmatrix('rans1_dynamicpoints.txt');
T = data(:,1);
T2 = data(:,2);
plot (T,T2,'x');
  1 件のコメント
muhammad choudhry
muhammad choudhry 2021 年 6 月 17 日
編集済み: muhammad choudhry 2021 年 6 月 17 日
Thanks for the reply, I was just going through how to plot , and find a way with . ...I will give it a read on the link you provide, Thanks again.
code below also works for me.
data = readtable ('rans1_dynamicpoints.txt');
plot (data.Var1,data.Var2)
hold on

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by