Create a matrix Z with m rows and n columns that contain the numbers 1 to m*n in ascending order in the following manner. The first row will contain numbers 1 to n. The second row will contain n+1 to 2n and so on. Thus, if m = 3, n = 4, the output matrix Z will have 3 rows and 4 columns and will be the following:
[1 2 3 4;
5 6 7 8;
9 10 11 12]
This become trivial if you use loops, but do this without using loops, i.e. for/while not permitted. Additionally, the reshape command makes this very easy, so avoid that as well.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers31
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6683 Solvers
-
4321 Solvers
-
324 Solvers
-
607 Solvers
-
644 Solvers
More from this Author52
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Your test suite detecting for loops is overzealous and trips up on arrayfun(..., "UniformOutput", false).
Fortunately, there is an abbreviation that can be used that will not be triggered by searches for "for": arrayfun(..., "Uni", 0). Incidentally, "Un" (or "un") can also be used while 0 is equivalent to false in this context. These abbreviations also work for cellfun.
Technically, arrayfun (cellfun as well) is just a loop in disguise. All in all, OP is asking for a vectorized solution.
@Dyuman You're right of course, but technically the problem description also says "do this without using loops, i.e. for/while not permitted", so arrayfun, cellfun and all the other kinds of fun that you can have with MATLAB are permitted. :)