Skip to content

YlmzCmlttn

Cemalettin Yılmaz Blog

Menu
  • Home
  • About Me
  • Projects
    • Iot-AR
    • Magnifi-AR
    • Smarthome-IOS
    • Others
  • Categories
    • Articles
    • Augmented Reality
    • Capture The Flag
      • Google CTF
        • 2018
    • Embedded Systems
    • IoT
    • Logisim
    • My Essays
    • Nvidia Jetson
      • Jetson TX1
    • Operating Systems
      • Kali
      • Raspbian
      • Ubuntu
    • Personal
    • Programming
      • Arduino
      • C
      • C#
      • Css
      • Html
      • Js
      • Matlab
      • Node.js
      • Python
      • Swift
      • VHDL
    • Projects
      • Embedded Systems
      • Electric
      • IoT
      • IoT-AR
      • Logisim
      • Magnifi-AR
      • Pose Estimation
    • Raspberry Pi
    • Xilinx
    • Others
Menu

Number of rectangles from unit squares | Matlab Examples

Posted on December 8, 2018February 20, 2019 by Yılmaz Cemalettin

Matlab Tutorials | Examples

Practice 13:

Number of rectangles from unit squares

Assume you are given an m×n rectangle of unit squares. Within this rectangle, many rectangles and squares can be formed by joining the unit squares.
Consider the 2×3 rectangle below.


There are 18 rectangles (some of them being squares) that you can construct using it:
A, AB, ABC, AD, ABDE, ABCDEF, B, BC, BE, BCEF, C, CF, D, DE, DEF, E, EF, F
Write a MATLAB program that gets the values m and n from the user. If either m or n is not a positive integer number, then the program should ask for that number again, until an acceptable value is given. The program should then count the number of rectangles/squares within the given m×n rectangle using loops, and display this number.

Solutions:

MATLAB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
clc
clear
%%Inputs for dimension of the rectangles
 
m = input('Enter m ');
while(m<0) || (m~=ceil(m)) %Checking the positive integer or not
    disp('The value must be a positive integer.')
    m = input('Enter m ');
end
n = input('Enter n ');
while(n<0) || (n~=ceil(n))%Checking the positive integer or not
    disp('The value must be a positive integer.')
    n = input('Enter n ');
end
 
%Calculating the numbers of the rectangle with in the for loop
 
total=0;
for i=1:m
for j=1:n
    total = total + i*j;
end
end
 
fprintf('Total number of rectangles inside a %gx%g rectangle of unit squares: %g\n',m,n,total);
 
%%Calculating the numbers of the rectangle with using Mathematical Formula
 
y = (1/4)*m*n*(m+1)*(n+1);
fprintf('Total number of rectangles inside a %gx%g rectangle of unit squares: %g (Using Mathematical Formula)\n',m,n,y);

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

My Motto

“Learn to share, Share to learn”

LinkedIn Badge

Cemalettin Yılmaz

Ads

Archives

Categories

  • Articles (1)
  • Augmented Reality (3)
  • Capture The Flag (23)
    • Google CTF (22)
      • 2018 (13)
      • 2019 (9)
    • PicoCTF (1)
      • 2019 (1)
  • Embedded Systems (3)
  • IoT (3)
  • Logisim (1)
  • My Essays (3)
  • Nvidia Jetson (5)
    • Xavier (5)
  • Operating Systems (24)
    • Kali (3)
    • Raspbian (2)
    • Ubuntu (21)
  • Others (1)
  • Personal (1)
  • Programming (44)
    • Arduino (4)
    • C (10)
    • C# (4)
    • C++ (5)
    • Css (1)
    • CUDA (6)
    • Html (1)
    • Js (2)
    • Libraries (5)
      • OpenCV (3)
      • OpenGL (2)
    • Matlab (14)
    • Node.js (5)
    • Python (6)
    • Swift (3)
  • Programs (4)
    • Tools (4)
  • Projects (21)
    • Books Solutions (8)
    • Electric (2)
    • Embedded Systems (2)
    • Energy Harvesting (1)
    • IoT (2)
    • IoT-AR (1)
    • Logisim (1)
    • Magnifi-AR (3)
    • Pose Estimation (3)
    • Smarthome-Ios (1)
  • Raspberry Pi (3)
  • Uncategorized (2)
  • YZlib (1)

Recent Posts

  • atof stof stod problems with local floating point separator in C/C++
  • Pico CTF 2019 Answers
  • YZlib: Personal C++ Library
  • Drive to target | Google CTF 2019
  • FriendSpaceBookPlusAllAccessRedPremium | Google CTF 2019

Recent Comments

  • AbaShelha on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Peter on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on 16-Bit CPU on Logisim
  • Jenny on 16-Bit CPU on Logisim
  • MOON on 16-Bit CPU on Logisim
  • anti on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • hunkerjr on STOP GAN | Google CTF 2019
  • Shaq on 16-Bit CPU on Logisim
  • NURUL AFIQAH MOHD HASBULLAH on 16-Bit CPU on Logisim

Linkedln

© 2022 YlmzCmlttn | Powered by Superbs Personal Blog theme