How to modify the code below so it can loop over certain files rather then 1?
2 views (last 30 days)
Show older comments
Hi, Below is the code which is reading one csv file I want to modify this code so it will read 100 csv files and produces 100 values of following [xc,yc,Re,a]. Quick modification would be helpful as deadline in an hour.
Code:
XY = dlmread('contours0.137.csv');
%
[xc,yc,Re,a] = circfit(XY(:,1),XY(:,2))
% reconstruct circle from data
n=100;
th = (0:n-1)/n*2*pi;
xe = Re*cos(th)+xc; ye = Re*sin(th)+yc;
figure(1),
plot(XY(:,1),XY(:,2),'b*',xe,ye,'r-'),
title(' measured fitted circles')
legend('measured','fitted')
text(xc-Re*0.9,yc,sprintf('center (%g , %g ); R=%g',xc,yc,Re))
% xlabel x, ylabel y
axis equal
2 Comments
Accepted Answer
KSSV
on 27 Oct 2020
Edited: KSSV
on 29 Oct 2020
csvFiles = dir("*.csv") ;
N = length(csvFiles) ;
C = zeros(N,3) ;
for i = 1:N
XY = dlmread(csvFiles(i).name);
[xc,yc,Re,a] = circfit(XY(:,1),XY(:,2));
C(i,:) = [xc yc Re] ;
% reconstruct circle from data
n=100;
th = (0:n-1)/n*2*pi;
xe = Re*cos(th)+xc; ye = Re*sin(th)+yc;
figure(1),
hold on
plot(XY(:,1),XY(:,2),'b*',xe,ye,'r-')
end
title(' measured fitted circles')
legend('measured','fitted')
text(xc-Re*0.9,yc,sprintf('center (%g , %g ); R=%g',xc,yc,Re))
% xlabel x, ylabel y
axis equal
5 Comments
More Answers (0)
See Also
Categories
Find more on Annotations 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!