MATLAB Answers

finding the file names with similar strings and group them together

13 views (last 30 days)
Zahra Sheikhbahaee
Zahra Sheikhbahaee on 17 Feb 2021
In a file I have a bunch of plots which I would like to plot the one which have the same hyper-parameters (values for given variable with slightly difference between names) side by side but I don't know whether I should extract the string of file names and find hyper parameters or there is a simpler way? Here is my code
im1='beta_win_loss_1.00_win_bias_0.60_context_rigid_1_win_optimism_0.65_win_optimism_rigid_1_risk_base_2_risk_val_4_No_optimism_0.65_No_optimism_rigid_100_loss_base_3_loss_val_3.jpg';
im2='noisy_cue_beta_win_loss_1.00_win_bias_0.60_context_rigid_1_optimism_0.65_optimism_rigid_1_risk_base_2_risk_val_4_No_optimism_0.65_No_optimism_rigid_100_loss_base_3_loss_val_3.jpg';
[X1,map1]=imread(im1);
[X2,map2]=imread(im2);
p1 = [0.0 0.0 0.5 1];
p2 = [0.5 0.0 0.5 1];
subplot('Position',p1), imshow(X1,map1,'Border','tight');
subplot('Position',p2), imshow(X2,map2,'Border','tight');
set(gcf, 'PaperUnits', 'inches');
x_width=8.25 ;
y_width=11.125;
set(gcf, 'PaperPosition', [0 0 x_width y_width]); %
img='combine_noisy_cue_beta_win_loss_1.00_win_bias_0.60_context_rigid_1_optimism_0.65_optimism_rigid_1_risk_base_2_risk_val_4_NoLoss_optimism_0.65_NoLoss_optimism_rigid_100_loss_base_3_loss_val_3.png';
print(gcf,img,'-dpng','-r400');
  3 Comments
Zahra Sheikhbahaee
Zahra Sheikhbahaee on 17 Feb 2021
What if I use these lines to compare two image names:
Num1=str2double(regexp(im1,'\d*','match')');
Num2=str2double(regexp(im2,'\d*','match')');
tf = isequal(Num1,Num2);
Now the problem is how to get list of images from files with a given pattern and loop over them. Any thoughts?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!