Creating a matrix within a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm having trouble on how to create an MxN matrix will all zeros and in that MxN matrix I want the the first column, first row, last row, and last column to be zeros while the rest of the matrix is all different numbers, with possible values as 0 zeros as well. An example is below,
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 0 1 0 1 1 1 1 1 0 0 0
0 0 1 1 0 1 0 0 0 1 1 1 1 0
0 1 0 1 1 1 1 0 1 0 1 0 1 0
0 1 0 0 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
Really the only values that the middle section can have is one or zero but the outsides have to all be zeros.
3 Kommentare
Akzeptierte Antwort
Matt J
am 21 Feb. 2013
Bearbeitet: Matt J
am 21 Feb. 2013
If you're saying you have a given matrix A and want to set the edges to zero,
A([1,end],[1,end])=0;
2 Kommentare
Matt J
am 21 Feb. 2013
Use randi() to generate random zeros and ones everywhere. Then use the code I showed you to set the boundaries to zero.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices 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!