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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:11:00+00:00 2026-06-09T21:11:00+00:00

Is there a way I can select a bunch of prespecified elements all at

  • 0

Is there a way I can select a bunch of prespecified elements all at once from a matrix? Specifically, suppose I have the following matrix:

      58        59        60       62        63        64
58  0.000000  3.772139  6.367721 8.978718 12.197210 13.401126
59  3.772139  0.000000  3.755554 5.935946  9.592700 11.664533
60  6.367721  3.755554  0.000000 5.999409  9.324764 11.991269
62  8.978718  5.935946  5.999409 0.000000  3.810169  6.762802
63 12.197210  9.592700  9.324764 3.810169  0.000000  3.796884
64 13.401126 11.664533 11.991269 6.762802  3.796884  0.000000

I want to select cells [1,2], [2,3], [3,4], [4,5], [5,6]. I realize that I can reference them by index, in this case I can run:

mymatrix[c(2,9,16,23,30)]

However, this is not very clear from reading the code later. Is there a way I can enter the actual (row, column) reference all at once?

  • 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-09T21:11:01+00:00Added an answer on June 9, 2026 at 9:11 pm

    Indexing can be done with 2 column matrices. After converting those row and column numbers to a valid R object (rather than Matlab-style expressions):

    > idxs <- gsub("\\]",")", gsub("\\[", "c(",  "[1,2], [2,3], [3,4], [4,5] ,[5,6]") )
    # I edited the string value that idxs returned:
    > midx <- rbind( c(1,2), c(2,3), c(3,4), c(4,5) ,c(5,6) )
    > mat <-  matrix(scan(), nrow=6)  
    1:  0.000000  3.772139  6.367721 8.978718 12.197210 13.401126
    7:   3.772139  0.000000  3.755554 5.935946  9.592700 11.664533
    13:   6.367721  3.755554  0.000000 5.999409  9.324764 11.991269
    19:   8.978718  5.935946  5.999409 0.000000  3.810169  6.762802
    25:  12.197210  9.592700  9.324764 3.810169  0.000000  3.796884
    31:  13.401126 11.664533 11.991269 6.762802  3.796884  0.000000
    37: 
    Read 36 items
    > mat[midx]
    [1] 3.772139 3.755554 5.999409 3.810169 3.796884
    

    If your goal were to index the super-diagonal that could be accomplished more generally:

    > mat[col(mat)==row(mat)+1]
    [1] 3.772139 3.755554 5.999409 3.810169 3.796884
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can do Select TableName.SomeColumn As SomeAlias FROM TableName In
Can anyone tell me if there is a way to select a video from
Is there a way I can select a portion of multiple lines in vim
Is there any way by which we can export the result of a select
Is there way that I can read the file from remote server using fopen
Is there any way we can fetch X509 Public Cetrificates using c# from AD
Is there a way I can use one category to stylize all of my
I have a query to the effect of SELECT t3.id, a,bunch,of,other,stuff FROM t1, t2,
Is there any way can declare a bean in just like JSP UseBean in
Is there any way I can set a formatter on models that will convert

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.