How do I plot an array// text file?

9 ビュー (過去 30 日間)
Krysten de Leon
Krysten de Leon 2020 年 5 月 3 日
コメント済み: Krysten de Leon 2020 年 5 月 3 日
For my code, I wanted to read a vertical array from a .txt file and make the content in the row the y coordinate and have the x coordinate be equal to the row number.
This is how the data in the file is formatted:
9.653679
10.760676
9.942204
9.807939
9.358463
10.937850
9.814911
10.688975
This is part of my code for plotting the graph. What I have now isn't producing a graph, it just has a blank window.
data = load(filename)
for i=1:1:length(data)
x = i;
y = data(1:i);
plot(x,y)
end
Any help would be great!

採用された回答

KSSV
KSSV 2020 年 5 月 3 日
編集済み: KSSV 2020 年 5 月 3 日
y = load(filename) ;
x = (1:length(y))' ; % making it a column as y is a column
plot(x,y)
Without using x also you can striaght away plot, it will be plotted w.r.t indices.
plot(y) ;
  1 件のコメント
Krysten de Leon
Krysten de Leon 2020 年 5 月 3 日
Thank you! That worked perfectly :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by