Table item number in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter Barnak
  • Start date Start date
  • Tags Tags
    Mathematica Table
Click For Summary

Discussion Overview

The discussion revolves around how to define tables in Mathematica that include the position of elements within the table. Participants explore various methods to achieve this, including using functions to replace elements with their indices and creating a function that generates an increasing integer each time it is called.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant seeks a method to include the position of elements in a Mathematica table, providing examples of desired outputs.
  • Another participant suggests using the ReplacePart function to modify elements in the table, emphasizing the importance of clarifying the question for better assistance.
  • A participant expresses confusion about the ongoing discussion and shares their own attempts to use ReplacePart to achieve the desired results.
  • There is a proposal for creating a function that returns an increasing integer each time it is called, with an example provided.
  • A later reply indicates that the last suggestion provided was the solution to the original problem, acknowledging the confusion in the initial query.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single method but explore multiple approaches to the problem. Some methods are proposed and refined, while others express confusion about the requirements.

Contextual Notes

Participants mention the need for clarity in the problem statement and the potential impact of previously assigned values on the results in Mathematica.

Who May Find This Useful

Users of Mathematica looking to manipulate tables and incorporate element positions, as well as those interested in creating functions that generate sequential integers.

Barnak
Messages
62
Reaction score
0
I need to define some "Tables" in Mathematica, in which some elements contains their own item number, like the following example below :

A := {a, b, 3 c, d}
B := {1, b, c, d}
C := {a, b, c, 4, d, e}
D := {a, 2, c, d, 5, g}

How can I do this ?
 
Physics news on Phys.org
I think you might want to make your question more precise and clear.

Is this anything like what you are looking for?

In[1]:= ReplacePart[ToExpression[Characters["abcdef"]],2,2]

Out[1]= {a,2,c,d,e,f}

You should recognize that if you have already assigned a value to any of a,b,...f that this will change the result.

In[2]:= a=7

Out[2]= 7

In[3]:= ReplacePart[ToExpression[Characters["abcdef"]],2,2]

Out[3]= {7,2,c,d,e,f}

If you can better explain what you really need then it is more likely that someone will be able to help you and more likely to provide the correct answer on the first try.
 
Sorry if I was obscure (and sorry for my bad English).

What I'm looking for is a way to make Mathematica tell what is the position of a given element in a table. The symbols "a", "b", "c" were just simple numbers in my examples above. For some elements, I want the element-position in the table to be printed, in the table itself.

Say we have this Table :

A := {123, 215, 456, 786}

I need to change it to something ike this :

A := {123, 2, 456, 4}

The second and fourth elements were changed by their position-number in their table.

EDIT : Maybe there's another way around my problem. Is there a way to print a always increasing positive integer, each time the function is called ? Let's call it ff[], then I need it to do the following in Mathematica :

In: ff[]
Out: 1

In: ff[]
Out: 2

In: ff[]
Out: 3

etc.
 
Last edited:
I'm sorry, but each new post makes me more confused than the last.

Maybe something in this will provide you a clue

In[1]:= A={123,215,456,786};A=ReplacePart[A,2,2]
Out[2]= {123,2,456,786}
In[3]:= A=ReplacePart[A,4,4]
Out[3]= {123,2,456,4}

In[4]:= ffcounter=1;ff[]:=ffcounter++;ff[]
Out[6]= 1

In[7]:= ff[]
Out[7]= 2

In[8]:= ff[]
Out[8]= 3

You appear to be groping around, hopefully knowing a good deal more about the problem you need to solve than you are providing here. That doesn't seem to be helping. Perhaps, just for a moment as an experiment, forget everything about Mathematica and just try to explain exactly what you are given and exactly what you then need to produce.
 
Okay thanks, the last suggestion was THE solution to my problem ! :smile:

Sorry if my query was all confused. I'm much too tired today, too impatient, and English isn't my native language. So I apologise for the troubles. :shy:

Anyway, you gave me the right solution ! Thank you very much again ... :cool:
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K