Create a matrix of 50 rows and 50 columns. The odd columns should contain values 2 and the even columns values 0
43 views (last 30 days)
Show older comments
Create a matrix of 50 rows and 50 columns. The odd columns should contain values 2 and the even columns values 0
0 Comments
Answers (1)
Image Analyst
on 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.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!