Problem 55220. Matrix Quadrants
Solution Stats
Problem Comments
-
3 Comments
Good problem!
function M = foursquare(N)
M = zeros(2*N);
for i=1:length(M)/2
for j=1:length(M)/2
M(i,j)=1;
j=j+1;
end
i=i+1;
end
for i=(length(M)/2)+1:length(M)
for j=(length(M)/2)+1:length(M)
M(i,j)=3;
j=j+1;
end
i=i+1;
end
end
Just wrote that program that gives me the right solution but I don't understand why it won't work.Any suggestions?
@Andreea you're hard-coding the value 3 on the twelfth line; the problem description says that the lower-left quadrant should contain N's instead.
Solution Comments
Show commentsProblem Recent Solvers435
Suggested Problems
-
Return the 3n+1 sequence for n
8227 Solvers
-
Return unique values without sorting
905 Solvers
-
Matlab Basics - Absolute Value
599 Solvers
-
Calculate the average value of the elements in the array
1124 Solvers
-
Find x rows where the sum of the numbers is the maximum
417 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!