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!