Natsortfiles for overlaying plots

2 views (last 30 days)
Manuella Juwita
Manuella Juwita on 30 Jun 2020
Commented: Stephen23 on 4 Jul 2020
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 Comments
Manuella Juwita
Manuella Juwita on 1 Jul 2020
Edited: Manuella Juwita on 1 Jul 2020
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 on 4 Jul 2020
The sunokest approach is probably just to generate the filenames using sprintf:

Sign in to comment.

Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!