How to make one element in a matrix the same for other elements?

What I mean by the question is the following:
Say I have matrix A and my A(2,1) = constant
Is there a way that I can write A(2,1)=A(2,1)=A(2,3) and so on?

2 commentaires

Can you explain a bit more? What exactly are you trying to do?
Bryan Galindo
Bryan Galindo le 1 Mai 2016
Modifié(e) : Bryan Galindo le 1 Mai 2016
What I'd like to do is have one element be the same value for various other elements.
The bigger picture of what I am trying to do however, is somewhat of a diagonal 11x11 matrix.
The A(1,1) and A(11,11) are their own unique values. (The first and last elements)
The middle rows in the diagonal (k=0) is X And the 2 other diagonals (k=1 & k=-1) is y
Example if it were a 4x4
A =
8 y 0 0
y x y 0
0 y x y
0 0 y 10
Sorry, I know it's a bit confusing.

Connectez-vous pour commenter.

 Réponse acceptée

Stephen23
Stephen23 le 1 Mai 2016
Modifié(e) : Stephen23 le 1 Mai 2016
>> x = 1;
>> y = 2;
>> N = 4; % size of the matrix
>> A = eye(N) * x;
>> A(1+1:1+N:end) = y;
>> A(1+N:1+N:end) = y;
>> A(1) = 8;
>> A(end) = 10
A =
8 2 0 0
2 1 2 0
0 2 1 2
0 0 2 10

3 commentaires

THANK YOU. Exactly what I was looking for.
Actually I have another question.
I have a 1xn matrix that have specific values at the ends but the middle values are all the same. How could I do this?
For example
C =
5
x
x
x
x
10
One solution:
C = ones(1,n) * x;
C(1) = 5;
C(end) = 10;
or you could try:
C = [5,x*ones(1,n-2),10]
note that these have different outputs for n<3.

Connectez-vous pour commenter.

Plus de réponses (1)

You want every other element in the second row to be set equal to the first element?
A(2,:) = A(2.1);
Or do you have other elements to be set? Your description is not very clear.

Catégories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by