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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:28:27+00:00 2026-05-28T21:28:27+00:00

I have two variables, the first is 1D flow vector containing 230 data and

  • 0

I have two variables, the first is 1D flow vector containing 230 data and the second is 2D temperature matrix (230*44219).

I am trying to find the correlation matrix between each flow value and corresponding 44219 temperature. This is my code below.

Houlgrave_flow_1981_2000 = window(Houlgrave_flow_average, start = as.Date("1981-11-15"),end = as.Date("2000-12-15")) 

> str(Houlgrave_flow_1981_2000)
‘zoo’ series from 1981-11-15 to 2000-12-15
Data: num [1:230] 0.085689 0.021437 0.000705 0 0.006969 ...
Index:  Date[1:230], format: "1981-11-15" "1981-12-15" "1982-01-15" "1982-02-15" ...

Hulgrave_SST_1981_2000=X_sst[1:230,]

> str(Hulgrave_SST_1981_2000)
num [1:230, 1:44219] -0.0733 0.432 0.2783 -0.1989 0.1028 ...

sf_Houlgrave_SF_SST = NULL
sst_Houlgrave_SF_SST = NULL
cor_Houlgrave_SF_SST = NULL
for (i in 1:230) {
     for(j in 1:44219){
          sf_Houlgrave_SF_SST[i] =  Houlgrave_flow_1981_2000[i]
          sst_Houlgrave_SF_SST[i,j] = Hulgrave_SST_1981_2000[i,j]
          cor_Houlgrave_SF_SST[i,j] = cor(sf_Houlgrave_SF_SST[i],Hulgrave_SST_1981_2000[i,j]) 
     }
}

The error message always says:

Error in sst_Houlgrave_SF_SST[i, j] = Hulgrave_SST_1981_2000[i, j] : 
  incorrect number of subscripts on matrix

Thank you for your help.

  • 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-28T21:28:27+00:00Added an answer on May 28, 2026 at 9:28 pm

    try this:

    # prepare empty matrix of correct size
    cor_Houlgrave_SF_SST <- matrix(nrow=dim(Hulgrave_SST_1981_2000)[1],
                                  ncol=dim(Hulgrave_SST_1981_2000)[2])
    
    # Good practice to not specify "230" or "44219" directly, instead
    for (i in 1:dim(Hulgrave_SST_1981_2000)[1]) {
      for(j in 1:dim(Hulgrave_SST_1981_2000)[2]){
         cor_Houlgrave_SF_SST[i,j] <- cor(sf_Houlgrave_SF_SST[i],Hulgrave_SST_1981_2000[i,j]) 
       }
    }
    

    The two redefinitions inside your loop were superfluous I believe. The main problem with your code was not defining the matrix – i.e. the cor variable did not have 2 dimensions, hence the error.
    It is apparently also good practice to define empty matrices for results in for-loops by explicitly giving them correct dimensions in advance – is meant to make the code more efficient.

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

Sidebar

Related Questions

I have two DateTime variables first period and second period and with each period
If I have two variables containing binary values, how do I append them together
From previous queries, I have two variables. The first: <list> <item>a</item> <item>b</item> <item>a</item> <item>c</item>
I have two data frames. The one consists of three variables, namely date, strike
I have two variables, key and value , and I want to add them
I have two variables: char charTime[] = TIME; char buf[] = SOMETHINGELSE; I want
If I have two variables: Object obj; String methodName = getName; Without knowing the
I have two string variables which are both file paths. The code that worked
Let's say I have two char variables, and later on I want to concatenate
I have two tables --> Variables (id, name) and Variable_Entries (id, var_id, value). I

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.