How to generate square-ish rectangle dimensions for any specified area

1 次查看(过去 30 天)
Hi all, given an arbitrary positive integer N, how can I calculate two integer factors A and B subject to A*B = N with the restriction that A should be close to B. In other words, if N is 12 then I would prefer the solution A=3,B=4 over A=2,B=6. Thanks!

采纳的回答

Image Analyst
Image Analyst 2014-5-3
Try this:
a=floor(sqrt(N)) % First integer less than sqrt.
b = ceil(N/a) % If fraction, make next largest integer.
  1 个评论
Eric Sampson
Eric Sampson 2014-5-3
Thanks IA, I knew it should be something like that but my brain is just a little fried at the end of the week. Have a great weekend! :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by