Natsortfiles for overlaying plots

조회 수: 2 (최근 30일)
Manuella Juwita
Manuella Juwita 2020년 6월 30일
댓글: Stephen23 2020년 7월 4일
I want to ask, how to use natsortfiles to sort alphanumerically overlaying plots in one figure? I find it difficult to match one plot to another because they have different directories and filenames
This is my code
% E = folder cropped greyscale
X = 'C:\Users\Lenovo\Documents\new matlab\hasil cacah 2\croppedk';
S = dir(fullfile(X,'*.jpg'));
contents = natsortfiles({S.name});
% I = folder contour
Y = 'C:\Users\Lenovo\Documents\new matlab\hasil cacah 2\contourk';
L = dir(fullfile(Y,'*.jpg'));
isi = natsortfiles({L.name});
for k = 1:numel(contents)
for i =1:numel(isi)
E = imread(fullfile(X,contents{k}));
% Make a truecolor all-green image.
green = cat(3, zeros(size(E)), ones(size(E)), zeros(size(E)));
hold on
h = imshow(green);
hold off
I = imread(fullfile(Y,isi{i}));
% green image.
set(h, 'AlphaData', I)
% Use our influence map image as the AlphaData for the solid
path = 'C:\Users\Lenovo\Documents\new matlab\hasil cacah 2\croppedk\zPlot';
saveas(gcf,fullfile(path,['zPlot' int2str(k) '.jpg']));
end
end
I want to overlay plots from different folders, folder 1 has filenames such as "gs1", "gs2" ,"gs3" ,"gs4" and folder 2 : "ax1"," ax2", "ax3" ,"ax4" so that i can overlay "gs1" with "ax1" and save as "z1", "gs2" with "ax2" and save as "z2", and so on.
  댓글 수: 3
Manuella Juwita
Manuella Juwita 2020년 7월 1일
편집: Manuella Juwita 2020년 7월 1일
Sorry about the confusion, yes I wanted to overlay plots from different folders, folder 1 has filenames such as "gs1", "gs2" ,"gs3" ,"gs4" and folder 2 : "ax1"," ax2", "ax3" ,"ax4" so that i can overlay "gs1" with "ax1" and save as "z1", "gs2" with "ax2" and save as "z2", and so on.
How can I achieve this? Thank you in advance, Stephen.
Stephen23
Stephen23 2020년 7월 4일
The sunokest approach is probably just to generate the filenames using sprintf:

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by