3
$\begingroup$

For example I have a matrix

A[1,1]={1,2,3,4};

Now I want to change the second element of A[1,1] to 5,so my code is

A[1,1][[2]]=5;

but there will be some error messages.
what I want to get is

A[1,1]={1,5,3,4};

What needs to be noted in particular is that the matrix A[1,1] must have double corner mark. Because there are lots of matrix in my actual code, and I should difference them.


I came up a way to settle this. But It's a bit of tedious.

For[n = 1, n <= nt, n = n + 1, For[i = 1, i <= it, i = i + 1, A[n, i] = Array[a[n, i], 4]]]

In this example

a[1,1][1]=1;a[1,1][2]=2;a[1,1][3]=3;a[1,1][4]=4;
a[1,1][2]=5;

Then I can get the A[1,1]={1,5,3,4};And I can handle the matrix with any corner mark.

$\endgroup$
  • $\begingroup$ I don't think it's useful, when working with Mathematica, to think of an expression such as A[1,1]={1,2,3,4}; as defining a matrix. It is, according to Mathematica syntax, the definition of a function called A and the value it takes when passed the arguments 1,1. Perhaps A is a function from the space of 2 integers into the space of lists of integers ? As for what you mean by the phrase corner mark, I don't know. $\endgroup$ – High Performance Mark Feb 15 at 9:47
7
$\begingroup$

Have a look at ReplacePart[]

A[1, 1] = {1, 2, 3, 4};
ReplacePart[A[1, 1], 2 -> 5]
{1, 5, 3, 4}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.