Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7161669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:36:19+00:00 2026-05-28T13:36:19+00:00

I searched the site but I could not find any solution to this problem.

  • 0

I searched the site but I could not find any solution to this problem. It is a pretty simple thing I am trying to accomplish, but I really cannot figure out how to do it.

I have a directory of images. I am running an experiment where, on a slider, people will rate how well two images relate to each other. Programming the slider part is easy in MATLAB. However, I am having a problem figuring out how to get the images to work. I want two pictures from the directory to appear randomly on the screen, such that by the end of the experiment every possible image pair will have been rated.

So if the images are:

dog
cat
mouse
hat

I want:

dog cat
dog mouse
dog hat
cat mouse
cat hat
mouse hat

How do I get MATLAB to do this?

First, I am having trouble getting it to display a random image in the first place. My script is something like this, but it doesn’t work:

dfiles = d(~[d.isdir]);
genRandNum = randperm(length(dfiles));
filename = dfiles(genRandNum(i)).name;
imageName = fullfile('Desktop', 'SEMREL', 'Pictures', filename);
imshow(imageName, 'Parent');

But once I get that working, how do I get it to display two images next to each other on the screen? And how do I weight the random generation so that I only get each image pair once? If I just tell it not to repeat an image that won’t work, because each individual image will have to be paired with several other images.

Help? I literally cannot find a way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:36:20+00:00Added an answer on May 28, 2026 at 1:36 pm

    Starting with your variable dfiles, you can generate a set of every possible two-image pairing using the functions NCHOOSEK and RANDPERM like so:

    nFiles = numel(dfiles);          %# The number of image files
    combos = nchoosek(1:nFiles, 2);  %# Create all unique index pairs
    combos = combos(randperm(size(combos, 1)), :);  %# Randomize the pair order
    

    And each row of combos will have a unique pair of indices into your set of image files stored in dfiles. Keep in mind that this could be a lot of unique pairings. For just 80 images, you will have 3,160 total pairwise combinations. That’s a very long experiment!

    With regard to displaying both images side-by-side, you can use SUBPLOT in conjunction with your calls to IMSHOW:

    subplot(1, 2, 1);
    imshow(imageName1);  %# Plot the first image
    subplot(1, 2, 2);
    imshow(imageName2);  %# Plot the second image
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just searched the web but could not find a good answer to this:
Preface: I am sure this is incredibly simple, but I have searched this site
I searched google but couldn't find an answer to this rather simple question. I
So I searched google and stackoverflow for a solution but I can not find
I searched all over this site and the web for a good and simple
I searched and found this question but did not like the answer. Is there
I have searched this site, and numerous others, looking for a solution to this
I have a dropdown box and a text box. I searched this site but
Please could anyone help me with this problem? The wordpress admin bar is not
I've searched their site. I just want to find the page number in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.