Problem 33. Create timestables
Solution Stats
Problem Comments

25 Comments
Cześć
it would seem that the recently added test#2 is incorrectly defined
Agree with Mr.Alfonso ; Test#2 is incorrectly defined
Agree with Mr.Alfonso ; Test#2 is incorrectly defined
Agree with Mr.Alfonso ; Test#2 is incorrectly defined
Agree with Mr.Alfonso ; Test#2 is incorrectly defined
Apparently the Cody Team can't make a times table. :p
Agree with the above
For those who wish to solve anyway: Make a correct solution that works with tests 1 and 3, and then hardcode an if with n==3 at the end to make solution 2 work
Sorry for the typo, I just fixed the test#2.
Good question!
How can people solve problem like this with a size 10 ?
Easy one
Easy one!
For a simple solution check out the matlab function kron
1
nice question
nice
good for beginners
why do you guys say nice question
so many possible solutions, just boils down to simplicity or creativity
Good problem!
Can be done in one line of code.
Interesting Problem
Great problem.
Solution Comments

2 Comments
good problem
I agree

1 Comment
moderately easy nice.

1 Comment
Challenging

1 Comment
That one was unique

1 Comment
m = [1:n]'*[1:n];

1 Comment
K = kron(1:n,1:n)
m = reshape(K,n,n)

1 Comment
Good Problem

5 Comments
function m = timestables(n)
y(1,1:n)=1:n;
y(1:n,1)=1:n;
for i=2:n
for j=2:n
y(i,j)=y(1,j)*y(i,1)
end
end
m = y;
end
a = repmat(1:n, n, 1);
m = a .* a';
or
m = (1:n) .* (1:n)';
m = (1:n)'*(1:n);
m = [1:n]'*[1:n];
what is the true leading solution?
thanks dawg

4 Comments
Please help me out,cant find out the error
I think the error is pretty clear. line3: column=1:1:n; line4:row=1:1:n.
besides, 1:n just fine, the "1" in the middle is quite not necessary.
what if i use 1:n and 1:1:n?both are same right? The step size is 1 for both the case. Tried what you said but Test suit fails again
two equal sign in line 3&4 are missed: this is fatal error, fix that, in my computer seems work fine. and 1:n is another problem, it can pass even you don't change it. nontheless, 1 in the middle is redundant. it CAN be removed, not like you have to.

2 Comments
How could you solve this by size 10?
hahahaha,hello~~

1 Comment
very easy

1 Comment
nice

1 Comment
On my matlab this code works for all the test, but here it fails, why?
m = reshape(1:n^2,[n,n])';
Moreover How can I see better solutions of the problem that I solved, so I can improve my Matlab skills?
Thank you very much for your attention

1 Comment
Sorry, I missed a ;)

1 Comment
Yeah,I did it.

1 Comment
Test solution 2 is incorrect, should be:
y_correct = [1 2 3; 2 4 6; 3 6 9]
current solution isn't even square...

1 Comment
The test suite is broken for this problem.

1 Comment
The second test should say y_correct = [1 2 3; 2 4 6;3 6 9];

2 Comments
can someone please tell me what I've done wrong here pls. Thanks
You've done nothing wrong; the solution to Test Suite #2 is incorrect.

1 Comment
No need to apply loop here, m=[1:n]'*[1:n] works fine.
function m = timestables(n)
m=(1:n)'*(1:n);
end

1 Comment
test # 2 is wrong, as it should be a 3x3 matrix,
y_correct for x=3 is:
[1 2 3; 2 4 6; 3 6 9]

1 Comment
Test nr. 2 seems not right: the soluton for x= 3 should be:
y_correct = [1 2 3; 2 4 6; 3 6 9]

1 Comment
lol

1 Comment
I tried on my matlab, it works.

1 Comment
this solution is correct... the answer for test #2 is incorrect.

1 Comment
Nice question. Good reminder how vector multiplication works.

1 Comment
Good

1 Comment
Pretty Cool

2 Comments
Duh! Thanks for reminding me how matrix multiplication works
good to learn with matrix scalar multiplication

1 Comment
it's correct for any value !!!!!

1 Comment
What, this is so weird!!!! Nice job

1 Comment
Missing semicolons...

1 Comment
l just wonder is it a real boring thing (times table),that we need to program it,for exam.12*12=144,almost everybody who atteded high school can answer,2^10=1024;25*25=625,13*13=169;14*14=196;15*15=225;it is such an easy thing that we needn't to make a table,we can calculate it out once we see such an multiplication

1 Comment
like your solution its very concise but there is one problem for me you have used '* for multiplication, can you please tell why?

1 Comment
function m = timestables(n)
for i=1:n
for j=1:n
m(i,j)=i*j;
end
end
%apparently this doesn't work even though MatLab says it works for any size

3 Comments
Brilliant!
After the solution I come up with ends up in the middle of the graph I feel disappointed. But then I learn there's a command that does something I didn't know about and I feel better about myself because I learned a new command!
amazing!

3 Comments
very elegant :)
nice :)
interesting approach, very smart!
Problem Recent Solvers13515
Suggested Problems

768 Solvers

838 Solvers

1485 Solvers

Longest run of consecutive numbers
3939 Solvers

509 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!