How to produce a matrix with the following conditions?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
M
am 13 Sep. 2022
Beantwortet: Walter Roberson
am 15 Sep. 2022
How to produce a matrix which size is 7*7 and contains all possible single locations of a certain value and the rest of the column's values are 1. For example : The value is 0.4 and I want to produce seven columns of different single locations of 0.4 and the other values are 1 such as: [0.4 1 1 1 1 1 1; 1 0.4 1 1 1 1 1; 1 1 0.4 1 1 1 1; 1 1 1 0.4 1 1 1; 1 1 1 1 0.4 1 1; 1 1 1 1 1 0.4 1; 1 1 1 1 1 1 0.4]
0 Kommentare
Akzeptierte Antwort
Sam Chak
am 13 Sep. 2022
2 Kommentare
Les Beckham
am 13 Sep. 2022
Or, with a few less steps:
M = ones(7);
M(logical(eye(7))) = 0.4
Weitere Antworten (1)
Walter Roberson
am 15 Sep. 2022
M = ones(7);
C = M;
C(logical(eye(7))) = 0.4
%or
M = ones(7);
C = M;
C(1:size(C,1)+1:end) = 0.4
%or
M = ones(7);
C = M - 0.6 * eye(size(M))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Discrete Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!