readmatrixで任意のファイルを指定してcsvを読み込みグラフを作成する方法を知りたいです。
265 views (last 30 days)
Show older comments
csvファイルを読み込みグラフを作ろうとしています。
a=readmatrix("sample1.csv");
plot([a(:,1)],[a(:,2)]);
[a(:,1)]は計測されたデータの時間軸で[a(:,2)]はプロットしたいデータになります。
sample1.csvのデータと同じパスにsample2.csv,sample3.csv...と別のデータがあるときに
a=readmatrix("sample2.csv");
plot([a(:,1)],[a(:,2)]);
のようにスクリプトを書き換えることなく、sample2.csvのデータ置かれているフォルダを開いてグラフ化したいデータを選ぶようにするにはどうしたらよいのでしようか。
0 Comments
Accepted Answer
Atsushi Ueno
on 9 Jul 2022
uigetfile関数を使います。
[file,path] = uigetfile('*.csv');
a=readmatrix([path file]);
plot([a(:,1)],[a(:,2)]);
More Answers (1)
Hernia Baby
on 9 Jul 2022
Edited: Hernia Baby
on 9 Jul 2022
こちらが参考になると思います。
------
list = dir('*.csv');
figure
hold on
for ii = 1:length(list)
a = readmatrix(list(ii).name);
plot(a(:,1),a(:,2))
end
0 Comments
See Also
Categories
Find more on テキスト ファイル in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!