Message Boards Message Boards

0
|
2042 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

[?] Get a part of the matrix?

Posted 5 years ago

I'm trying to extract a 5x5 part of a 1200x1500 matrix around the max of the matrix. To find the max i use:

Max[DivdLight[[1]]]

and to find the corresponding row and column i use:

 Position[DivdLight[[1]],Max[DivdLight[[1]]]

Now to get out a 5x5 about the max point i use: DivdLight[[1]][[tx - 5 ;; tx + 5, ty - 5 ;; ty + 5]] and i get the following error: Error message

But if i put in the number, without call from the list like:

DivdLight[[1]][[481- 5 ;; 481 + 5, 835 - 5 ;; 835 + 5]]

then the code works as intended

do you guys have any idea why that's the case? And if so help please

POSTED BY: Pruthvi Acharya

Pruthvi,

Your tx is a list, not a number:

In[1]:= array = RandomReal[{-10,10},{500,600}];
In[2]:= pos = Position[array,Max[array]][[1]]
Out[2]= {112,479}
In[3]:= abs = array[[pos[[1]]-5;;pos[[1]]+5,pos[[2]]-5;;pos[[2]]+5]];
In[4]:= abs//Dimensions
Out[4]= {11,11}

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract