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 CenterFile Exchange에서 Medical Physics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by