Run script while changing different paths
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
Ken Atwell
am 2 Mär. 2019
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)
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!