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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:33:32+00:00 2026-05-23T12:33:32+00:00

I would like your help on something, I have a Table: InitialMatrix[x_, y_, age_,

  • 0

I would like your help on something,

I have a Table:

InitialMatrix[x_, y_, age_, disease_] :=

  ReplacePart[Table[Floor[Divide[dogpopulation/cellsno,9]], {x}, {y}, {age}, {disease}], 
{{_, _, 1, _} ->  0, {_, _, 3, _} -> 6}];

I was trying to set up a condition to change all the values inside the table to sumthing else, according to a value, I tried:

listInitial={};

For[a = 1, a < 4, a++,

 For[b = 1, b < 4, b++,

  For[x = 1, x < 4, x = x + 1,

   For[z = 1, z < 4, z = z + 1,

 listInitial =

 If[Random[] > psurvival, 

      ReplacePart[ InitialMatrix[3, 3, 3, 3], {a, b, x, z} -> 
        InitialMatrix[3, 3, 3, 3][[a]][[b]][[x]][[z]] - 1], 

      InitialMatrix[3, 3, 3, 3], {a, b, x, z} -> 
       InitialMatrix[3, 3, 3, 3][[a]][[b]][[x]][[z]]]]]]]

but it only changes the last part of my table, finally I decided to use the following code instead of the for loop,

SetAttributes[myFunction, Listable]

myFunction[x_] := 
 If[Random[] > psurvival, If [x - 1 < 0 , x , x - 1], x]

 myFunction[InitialMatrix[3, 3, 3, 3]] // TableForm

but now I want to change specific parts inside the table, for example I want all the part
{__,__,3,_} to change I tried to choose the range with MapAt but again I think I need to do a loop, and I cannot, can any one please help me?

For[x = 1, x < 4, x++,
  listab[MapAt[f, InitialMatrix[3, 3, 3, 3], {x, 3, 3}]//TableForm]]
  • 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-23T12:33:33+00:00Added an answer on May 23, 2026 at 12:33 pm

    If you check out the documentation for MapAt, you will see that you can address multiple elements at various depths of your tensor, using various settings of the third argument. Note also the use of Flatten’s second argument. I think this is what you are looking for.

    MapAt[g, InitialMatrix[3, 3, 3, 3], 
    Flatten[Table[{i, j, 3, k}, {i, 3}, {j, 3}, {k, 3}], 2]]
    

    http://reference.wolfram.com/mathematica/ref/MapAt.html
    http://reference.wolfram.com/mathematica/ref/Flatten.html

    Since this seems to be your second attempt to ask a question involving a really complicated For loop, may I just emphasise that you almost never need a For or Do loop in Mathematica in the circumstances where you would use one in, say, Fortran or C. Certainly not for most construction of lists. Table works. So do things like Listable functions (which I know you know) and commands like NestList, FoldList and Array.

    You will probably also find this tutorial useful.
    http://reference.wolfram.com/mathematica/tutorial/SelectingPartsOfExpressionsWithFunctions.html

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

Sidebar

Related Questions

I would like your help with something that I have searched a lot but
I would just like your feedback on something. Basically I have a value called
Would appreciate your help with something. I have an autoclick Greasemonkey for Firefox script
I would really like your help in knowing the procedure to delete a .3gp
I have one query on which I would like to get your valuable feedback.
I have a little experience with WCF and would like to get your opinion/suggestion
I would like your guidance on how to create classes and their relationships (generalization,
I would like your advice about how best to solve my problem. In a
As I am new to this I would like your advice. So far I
I would like to get your opinion on as how far to go with

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.