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

  • Home
  • SEARCH
  • 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 8728423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:38:13+00:00 2026-06-13T08:38:13+00:00

I have a cell array of strings (which is actually a list of files

  • 0

I have a cell array of strings (which is actually a list of files selected by the user). I would then like to bring up a user interface control that allows the user to manually reorder that list.

Essentially I would like the user to be able to select the order in which the files given are processed. Is there a piece of code already that does this or does anybody have any good suggestions for how to do this?

Ideally it would show the list of strings (file names) and you could click on one and click an up or down arrow to move it up or down in the list, or for bonus points 😛 it would allow for dragging them to reorder (though I doubt such a thing exists for matlab GUI).

  • 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-06-13T08:38:14+00:00Added an answer on June 13, 2026 at 8:38 am

    There’s no native support for this in Matlab. The easiest solution is to use a uitable with “some hacks”.

    The solution shown below works for selection of single cell in the table, or multiple cells. Bounds are maintained, i.e., values do not “wrap around”.

    function reorderableTable
    
        h(1) = figure(1); clf
    
        filenames = {...
            'file1.txt.'
            'file2.txt.'
            'file3.txt.'
            'file4.txt.'
            'file5.txt.'
            };
    
        h(2) = uitable(h(1),...
            'data'    , filenames, ...
            'units'   , 'normalized',...
            'position', [0.1 0.1 0.5 0.85],...
            'CellSelectionCallback', @selectCells);
    
        h(3) = uicontrol(...
            'style'   , 'pushbutton', ...
            'units'   , 'normalized',...
            'position', [0.7 0.58 0.2 0.15],...
            'string'  , 'Up',...
            'callback', @reOrder);
        h(4) = uicontrol(...
            'style'   , 'pushbutton', ...
            'units'   , 'normalized',...
            'position', [0.7 0.38 0.2 0.15],...
            'string'  , 'Down',...
            'callback', @reOrder);
    
        set(h(3:4), 'enable', 'off');
    
        function selectCells(src, evt)
            set(src, 'UserData', evt.Indices);
            if ~isempty(evt.Indices)
                set(h(3:4), 'enable', 'on');
            else
                set(h(3:4), 'enable', 'off');
            end
        end
    
        function reOrder(src,~)
    
            up = strcmpi(get(src, 'string'), 'up');
    
            table = h(2);
            data = get(table, 'Data');
            selected = get(table, 'UserData');        
            selected = selected(:,1);
    
            if up
    
                sel  = selected-1;
                not_selected = setdiff(sel, selected);            
                nsel = setdiff(selected, sel);
    
                if sel(1)>=1 && nsel(end)<=size(data,1)
                    new_data = data;
                    new_data(sel ,:) = data(selected,:);
                    new_data(nsel,:) = data(not_selected,:);            
                else
                    return
                end   
    
            else
                sel  = selected+1;
                not_selected = setdiff(sel, selected);            
                nsel = setdiff(selected, sel);          
    
                if sel(1)<=size(data,1) && nsel(end)>=1
                    new_data = data;
                    new_data(sel ,:) = data(selected,:);
                    new_data(nsel,:) = data(not_selected,:);                
                else
                    return
                end
    
            end
    
            set(table, 'Data', new_data);
        end
    end
    

    Inspiration (partly) came from here.

    If you don’t like nested functions it’s easy to redefine them as subfunctions, but then you’ll have to pass the handles around (which is why I opted to use nested functions in the first place).

    Dragging-and-dropping: it can be done natively, but only on uitable columns (see this link). This I think will look horrendous, but might just work if you only have one or two files.

    Otherwise: you can use the buttons as shown above, or google around a bit to see if there is some other Java object (other than jTable) that does allow you to drag rows about. I’m not intimately familiar with Java, so you’ll have to look elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cell array of anonymous function handles, and would like to create
I have a Nx4 cell array in Matlab which looks something like this: id1
I have a list (cell array) of elements with structs like this: mystruct =
I have a cell array which contains 7 matrices of varying column and length
I have a cell in which the user enters their name, a serial number
I have a large alphabetically ordered cell array of strings (~495 thousand), with lots
I have the following code which fetches a string from an array of strings
I have a cell array, x, and each row of which is a string
I have a cell array like a={'potential'; 'impact'; 'of'; 'stranded'; 'assets'; 'and'; 'other'; 'necessary';
i have a cell array as below, which are dates. I am wondering how

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.