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 8535255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:23:23+00:00 2026-06-11T10:23:23+00:00

I have data like the following matrix: A = [2 5 10 4 10;

  • 0

I have data like the following matrix:
A = [2 5 10 4 10; 2 4 5 1 2; 6 2 1 5 4];

A =

 2     5    10     4    10
 2     4     5     1     2
 6     2     1     5     4

I would like to sort the by the last row based on the following criteria:

if the difference between the first element (in the third row) and second element (in the third row) is less than or equal to 2 — then move that column (the second in this case two columns to the right). Then do this for all columns until no two elements (of the last row) are within a difference of 2)

B =

 2     5     4    10    10
 2     4     1     5     2
 6     2     5     1     4

Where (6-2 = 4) (2-5 = 3) (5-1 = 4) (1-4 = 3)

Ultimately difference between all elements of the last row and element next to it is greater than 2.

Any suggestions?

  • 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-11T10:23:24+00:00Added an answer on June 11, 2026 at 10:23 am

    This is one possible solution:

    A = [2 5 10 4 10; 2 4 5 1 2; 6 2 1 5 4];
    
    B = A;
    
    MatrixWidth = size(A, 2);
    
    CurIndex = 1;
    
    %# The second-last pair of the bottom row is the last pair to be compared.
    while(CurIndex+2 <= MatrixWidth)
        Difference = abs(A(3,CurIndex) - A(3,CurIndex+1));
    
        %# If the right side of comparison is not yet the second-last index.
        if ((Difference <= 2) && (CurIndex+3 <= MatrixWidth))
            B = [ B(:, 1:CurIndex), B(:, CurIndex+2), B(:, CurIndex+1), B(:, CurIndex+3:end) ];
        %# If the right side of the comparison is already the second-last index.
        elseif (Difference <= 2)
            B = [ B(:, 1:CurIndex), B(:, CurIndex+2), B(:, CurIndex+1) ];
        end
    
        CurIndex = CurIndex + 1;
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix of data (with row names and column names). I would
I would like to have a 3d plot with matplotlib. Data are the following:
I have data like the following: var data = [{ id: 1, date: new
I have some data formated like the following 2009.07.02 02:20:14 40.3727 28.2330 6.4 2.6
I have a JavaScript data structure like the following in my Node.js/Express web app:
I have a data file that looks like the following example. I've added '%'
I have a data source with about 2000 lines that look like the following:
I have some data in a table that looks roughly like the following: table
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
I have some html like the following: <div class=control-group> <input type=text data-bind=value: $data.DealCode name=DealCode

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.