Image file saving location

1 Ansicht (letzte 30 Tage)
형준 이
형준 이 am 19 Mai 2022
Kommentiert: 형준 이 am 19 Mai 2022
my code ↓
for i = 1:5
h = imagesc(X, Y, Z(:,:,i)); xlim([-2 2]); ylim([-1 1]);
fname = ['Image', num2str(i)];
print(fname, '-djpeg');
end
How do I save the image file to folder 'C:\Users\leehj\Desktop\aaa' ?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Mai 2022
outdir = 'C:\Users\leehj\Desktop\aaa';
for i = 1:5
h = imagesc(X, Y, Z(:,:,i)); xlim([-2 2]); ylim([-1 1]);
fname = fullfile(outdir, ['Image', num2str(i)]);
print(fname, '-djpeg');
end
  2 Kommentare
Walter Roberson
Walter Roberson am 19 Mai 2022
Bearbeitet: Walter Roberson am 19 Mai 2022
Note: with modern MATLAB, you should consider using exportgraphics() .
Also you should probably include the file extension.
There are also nicer ways to construct the name,
outdir = "C:\Users\leehj\Desktop\aaa";
ax = gca;
for i = 1:5
imagesc(ax, X, Y, Z(:,:,i)); xlim([-2 2]); ylim([-1 1]);
fname = fullfile(outdir, "Image" + i + ".jpg");
exportgraphics(ax, fname);
end
형준 이
형준 이 am 19 Mai 2022
thank you ver much :- )

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 19 Mai 2022
thepath = 'C:\Users\leehj\Desktop\aaa\' ;
for i = 1:5
h = imagesc(X, Y, Z(:,:,i)); xlim([-2 2]); ylim([-1 1]);
fname = [thepath,'Image', num2str(i)];
print(fname, '-djpeg');
end

Community Treasure Hunt

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

Start Hunting!

Translated by