Run script while changing different paths

1 回表示 (過去 30 日間)
Sanchit Sharma
Sanchit Sharma 2019 年 3 月 2 日
回答済み: Ken Atwell 2019 年 3 月 2 日
Hi I have a folder with many subfolders labeled 1-100. I want to run same script for data stored in each of these folders. i.e. the script first runs for folder1 then for folder2 till folder 100. my script is as follows:
for k=1:100
cd ('C:\Users\sanchitsharma\Desktop\Run\%k',k)
pixarray = zeros(256*11,256*11);
for i = 0:255
filename = strcat("eDep", num2str(i), ".csv");
E = importdata(filename,',', 3);
E=E.data;
coord = E(:,1:2);
nrg = E(:,4);
for j=1:length(nrg)
if ~(nrg(j) == 0 )
pixarray(i*11 + coord(j,1)+1,coord(j,2)+1) = nrg(j);
end
end
filename = strcat("eDepL", num2str(i), ".csv");
E = importdata(filename,',', 3);
E=E.data;
coord = E(:,1:2);
nrg = E(:,4);
for j=1:length(nrg)
if ~(nrg(j) == 0 )
pixarray(i*11 + coord(j,1)+8,coord(j,2)+1) = nrg(j);
end
end
end
A=figure(4);
imshow(pixarray,[]);
colormap jet;
colorbar;
% saveas(gcf,'%k.png');
saveas(A,sprintf('FIG%k.png',k))
B=figure(5);
binaryim = pixarray; binaryim(binaryim>0)=1;
imshow(binaryim,[]);
saveas(B,sprintf('BIN%k.png',k))
end
This does not work can you please recommend me a solution. Thanks!

回答 (1 件)

Ken Atwell
Ken Atwell 2019 年 3 月 2 日
You did not specify the error you see, but I can see a problem with the cd command. It only take one argument, but you are passing in two.
Try this: Replace:
cd ('C:\Users\sanchitsharma\Desktop\Run\%k',k)
with:
cd ("C:\Users\sanchitsharma\Desktop\Run\"+k)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by