Create loop for reading CSV file, runing and saveing the plot of it

2 ビュー (過去 30 日間)
Masoud Taleb
Masoud Taleb 2021 年 8 月 23 日
コメント済み: dpb 2021 年 8 月 23 日
Hello
I have a code that works for a single CSV file and saves the plot at the end. Now, I have 300 of these CSV files and need to speed up my work. The problem is that file names are a little bit complecated and I need the plot to be still saved with similar name as its original CSV file. I hope someone can help me in this. So, in summert the question is how to make a loop for runing files and save resulting plot with a specific name (such as its CSV file name or other distingushed name)?
I put my code here:
[file,path] = uigetfile('*.*');
A = readmatrix([path file]);
theta = A(2:end, 1);
phi = A(1, 2:end);
data = A(2:end,2:end);
data = max(data,0);
[x,y]= meshgrid(theta,phi);
y=cos(phi).*theta;
x=sin(phi).*theta;
figure; pcolor(x,y,data);axis equal;shading flat
colormap(hot)
saveas(gcf,'AR3_20.0 um.png')

回答 (1 件)

dpb
dpb 2021 年 8 月 23 日
There's also a fancy thing called a "tabular text datastore" that is a container for the dir() solution in the above link.
  2 件のコメント
Masoud Taleb
Masoud Taleb 2021 年 8 月 23 日
Thanks for the tip; but was too complecated to me. Do you know how should I apply it in my code? I am pretty begginer in the world of Matlab. :)
dpb
dpb 2021 年 8 月 23 日
Use dir() to return the list of files with an appropriate wildcard for the filename and then iterate over the number returned as the example shows.
Just start by pulling the pieces of the example and making them fit your variables -- it's not as complicated as it seems but you have to "just begin"...

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by