How to generate square-ish rectangle dimensions for any specified area
2 ビュー (過去 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!
0 件のコメント
採用された回答
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!