Matlab Question: How to assign a new name to an amended matrix

In summary, you can replace columns in a matrix by copying the original matrix and replacing the desired column with a vector. It is also possible to amend the original matrix and assign the result a new name, using syntax similar to the one shown above.
  • #1
Steve Collins
46
0
I have to replace some matrix columns with some vectors. I am currently copying the original matrix and replacing the column of the matrix I have copied eg:

matrix_1 = matrix_2
matrix_2(:,4) = vector_1

This works fine, but I was wondering if it was possible to maybe amend the original matrix and assign the result a new name?

something like:

(matrix_1(:,4) = vector_1) = matrix_2 'I know this is nonsense, I'm just trying to explain what I mean.'

You can probably tell that I have only just picked up the Matlab book so please bear in mind that my knowledge is very very basic.

Thanks

Steve
 
Physics news on Phys.org
  • #2
Yes, you can do this. The syntax would look something like this:matrix_2 = matrix_1;matrix_2(:,4) = vector_1;
 

FAQ: Matlab Question: How to assign a new name to an amended matrix

What is the purpose of assigning a new name to an amended matrix in Matlab?

Assigning a new name to an amended matrix in Matlab allows you to save the changes made to the original matrix without overwriting it. This can be useful if you want to keep the original matrix for future use while also having a modified version.

How can I assign a new name to an amended matrix in Matlab?

To assign a new name to an amended matrix in Matlab, you can use the assignment operator (=) followed by the new name and the amended matrix. For example, if the original matrix is named A and the amended matrix is B, you can use the code: B = A;

Can I assign a new name to an amended matrix without creating a new variable?

Yes, you can assign a new name to an amended matrix without creating a new variable by using the "indirect assignment" method. This involves using the colon operator (:), which creates a temporary variable in the background. For example, if the original matrix is named A and the amended matrix is B, you can use the code: A(:) = B;

Is it possible to assign a new name to an amended matrix and the original matrix at the same time?

Yes, it is possible to assign a new name to an amended matrix and the original matrix at the same time by using the "direct assignment" method. This involves using the equals operator (==) followed by the new name and the original matrix, and then using the assignment operator (=) followed by the new name and the amended matrix. For example, if the original matrix is named A and the amended matrix is B, you can use the code: A == B; A = B;

What happens if I assign a new name to an amended matrix and then make changes to the original matrix?

If you assign a new name to an amended matrix and then make changes to the original matrix, the changes will not be reflected in the amended matrix. This is because the amended matrix is a separate entity with its own values and is not linked to the original matrix. If you want the amended matrix to reflect the changes made to the original matrix, you will need to reassign the amended matrix again.

Similar threads

Replies
1
Views
3K
Replies
1
Views
2K
Replies
1
Views
4K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
2
Views
6K
Back
Top