How to store the following Matrix in a variable?

6 visualizzazioni (ultimi 30 giorni)
How to store the following Matrix in the variable C?
I got the following error
M = ones(7);
C = M(logical(eye(7))) = 0.4
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON

Risposta accettata

Walter Roberson
Walter Roberson il 15 Set 2022
M = ones(7);
C = M;
C(logical(eye(7))) = 0.4
C = 7×7
0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000
%or
M = ones(7);
C = M;
C(1:size(C,1)+1:end) = 0.4
C = 7×7
0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000
%or
M = ones(7);
C = M - 0.6 * eye(size(M))
C = 7×7
0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.4000

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by