Create a matrix of 50 rows and 50 columns. The odd columns should contain values 2 and the even columns values 0

43 vues (au cours des 30 derniers jours)
Create a matrix of 50 rows and 50 columns. The odd columns should contain values 2 and the even columns values 0

Réponses (1)

Image Analyst
Image Analyst le 20 Oct 2021
There are several ways to do this. What did you try? You can do it in 2 lines of code. Here is the first one:
m = zeros(50,50); % Create a 50x50 matrix of all zeros.
Use simple indexing to assign the value 2 to all elements in the columns 1,3,5,7,...49.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by