Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Figures are not saving as the correct size when put into a PDF

Figures are not saving as the correct size when put into a PDF

PuTI / 2025-03-19
Figures are not saving as the correct size when put into a PDF
Matlab News

Please, I would appreciate any help as I have been stuck on this question for days. I have coded a loop that takes images from a folder and puts them in a 2×2 table and automatically numbers them. It creates a figure with the four images on it. It repeats this process until all the images have been used. Then it creates a PDF with all the figures saved, e.g. one figure of four images per page. My issue is, I need the figures to be in the centre of a landscape page, with white space margins around this. Currently, the images look fine on the figure display when you run the code, but when I open up the PDF, they take up the entire page and leave no margin space. I’ll insert two images of what I currently get, and what I need to produce. I would be so so appreciative of anyone that can help me please. Each image needs to be 10cm width by 7cm height on a landscape page in the final PDF.
Coding is not my strongest suit so I apologise if I have mistakenly used the wrong terminology. Thank you in advance.
Here’s the relevant parts of my code.
% Define the desired figure size in inches
figureWidth = 11.7; % Total width of the figure in inches
figureHeight = 8.3; % Total height of the figure in inches

% Define the desired image size in centimeters
imageWidth_cm = 10; % Width of each image in centimeters
imageHeight_cm = 7.5; % Height of each image in centimeters

% Convert image size from centimeters to inches
imageWidth_inch = imageWidth_cm / 2.54; % Convert cm to inches
imageHeight_inch = imageHeight_cm / 2.54; % Convert cm to inches

% Define the spacing between images (in inches)
horizontalSpacing = 0.5; % Spacing between images horizontally
verticalSpacing = 0.5; % Spacing between images vertically

% Calculate the total width and height required for the 2×2 grid
totalWidth = 2 * imageWidth_inch + horizontalSpacing;
totalHeight = 2 * imageHeight_inch + verticalSpacing;

% Calculate the left and bottom margins to center the grid
leftMargin = (figureWidth – totalWidth) / 2;
bottomMargin = (figureHeight – totalHeight) / 2;

% Initialize a cell array to store figure handles
figures = cell(numTables, 1);

% Calculate the position of the subplot
subplotX = leftMargin + mod(i – 1, 2) * (imageWidth_inch + horizontalSpacing);
subplotY = bottomMargin + floor((i – 1) / 2) * (imageHeight_inch + verticalSpacing);

% Create a subplot for each image
axes(‘Position’, [subplotX / figureWidth, subplotY / figureHeight, imageWidth_inch / figureWidth, imageHeight_inch / figureHeight]);
imshow(img);
axis off;
% Save the figure as a high-resolution image
outputFileName = fullfile(outputFolder, [‘Figure_’, num2str(tableIdx), ‘.png’]);
exportgraphics(fig, outputFileName, ‘Resolution’, 300);
outputPDF = fullfile(outputFolder, ‘output.pdf’); % Define the output PDF file
for i = 1:numTables
% Export the figure to the PDF
exportgraphics(figures{i}, outputPDF, ‘Resolution’, 300, ‘Append’, i > 1, ‘ContentType’, ‘vector’, ‘Padding’, 0.5);
endPlease, I would appreciate any help as I have been stuck on this question for days. I have coded a loop that takes images from a folder and puts them in a 2×2 table and automatically numbers them. It creates a figure with the four images on it. It repeats this process until all the images have been used. Then it creates a PDF with all the figures saved, e.g. one figure of four images per page. My issue is, I need the figures to be in the centre of a landscape page, with white space margins around this. Currently, the images look fine on the figure display when you run the code, but when I open up the PDF, they take up the entire page and leave no margin space. I’ll insert two images of what I currently get, and what I need to produce. I would be so so appreciative of anyone that can help me please. Each image needs to be 10cm width by 7cm height on a landscape page in the final PDF.
Coding is not my strongest suit so I apologise if I have mistakenly used the wrong terminology. Thank you in advance.
Here’s the relevant parts of my code.
% Define the desired figure size in inches
figureWidth = 11.7; % Total width of the figure in inches
figureHeight = 8.3; % Total height of the figure in inches

% Define the desired image size in centimeters
imageWidth_cm = 10; % Width of each image in centimeters
imageHeight_cm = 7.5; % Height of each image in centimeters

% Convert image size from centimeters to inches
imageWidth_inch = imageWidth_cm / 2.54; % Convert cm to inches
imageHeight_inch = imageHeight_cm / 2.54; % Convert cm to inches

% Define the spacing between images (in inches)
horizontalSpacing = 0.5; % Spacing between images horizontally
verticalSpacing = 0.5; % Spacing between images vertically

% Calculate the total width and height required for the 2×2 grid
totalWidth = 2 * imageWidth_inch + horizontalSpacing;
totalHeight = 2 * imageHeight_inch + verticalSpacing;

% Calculate the left and bottom margins to center the grid
leftMargin = (figureWidth – totalWidth) / 2;
bottomMargin = (figureHeight – totalHeight) / 2;

% Initialize a cell array to store figure handles
figures = cell(numTables, 1);

% Calculate the position of the subplot
subplotX = leftMargin + mod(i – 1, 2) * (imageWidth_inch + horizontalSpacing);
subplotY = bottomMargin + floor((i – 1) / 2) * (imageHeight_inch + verticalSpacing);

% Create a subplot for each image
axes(‘Position’, [subplotX / figureWidth, subplotY / figureHeight, imageWidth_inch / figureWidth, imageHeight_inch / figureHeight]);
imshow(img);
axis off;
% Save the figure as a high-resolution image
outputFileName = fullfile(outputFolder, [‘Figure_’, num2str(tableIdx), ‘.png’]);
exportgraphics(fig, outputFileName, ‘Resolution’, 300);
outputPDF = fullfile(outputFolder, ‘output.pdf’); % Define the output PDF file
for i = 1:numTables
% Export the figure to the PDF
exportgraphics(figures{i}, outputPDF, ‘Resolution’, 300, ‘Append’, i > 1, ‘ContentType’, ‘vector’, ‘Padding’, 0.5);
end Please, I would appreciate any help as I have been stuck on this question for days. I have coded a loop that takes images from a folder and puts them in a 2×2 table and automatically numbers them. It creates a figure with the four images on it. It repeats this process until all the images have been used. Then it creates a PDF with all the figures saved, e.g. one figure of four images per page. My issue is, I need the figures to be in the centre of a landscape page, with white space margins around this. Currently, the images look fine on the figure display when you run the code, but when I open up the PDF, they take up the entire page and leave no margin space. I’ll insert two images of what I currently get, and what I need to produce. I would be so so appreciative of anyone that can help me please. Each image needs to be 10cm width by 7cm height on a landscape page in the final PDF.
Coding is not my strongest suit so I apologise if I have mistakenly used the wrong terminology. Thank you in advance.
Here’s the relevant parts of my code.
% Define the desired figure size in inches
figureWidth = 11.7; % Total width of the figure in inches
figureHeight = 8.3; % Total height of the figure in inches

% Define the desired image size in centimeters
imageWidth_cm = 10; % Width of each image in centimeters
imageHeight_cm = 7.5; % Height of each image in centimeters

% Convert image size from centimeters to inches
imageWidth_inch = imageWidth_cm / 2.54; % Convert cm to inches
imageHeight_inch = imageHeight_cm / 2.54; % Convert cm to inches

% Define the spacing between images (in inches)
horizontalSpacing = 0.5; % Spacing between images horizontally
verticalSpacing = 0.5; % Spacing between images vertically

% Calculate the total width and height required for the 2×2 grid
totalWidth = 2 * imageWidth_inch + horizontalSpacing;
totalHeight = 2 * imageHeight_inch + verticalSpacing;

% Calculate the left and bottom margins to center the grid
leftMargin = (figureWidth – totalWidth) / 2;
bottomMargin = (figureHeight – totalHeight) / 2;

% Initialize a cell array to store figure handles
figures = cell(numTables, 1);

% Calculate the position of the subplot
subplotX = leftMargin + mod(i – 1, 2) * (imageWidth_inch + horizontalSpacing);
subplotY = bottomMargin + floor((i – 1) / 2) * (imageHeight_inch + verticalSpacing);

% Create a subplot for each image
axes(‘Position’, [subplotX / figureWidth, subplotY / figureHeight, imageWidth_inch / figureWidth, imageHeight_inch / figureHeight]);
imshow(img);
axis off;
% Save the figure as a high-resolution image
outputFileName = fullfile(outputFolder, [‘Figure_’, num2str(tableIdx), ‘.png’]);
exportgraphics(fig, outputFileName, ‘Resolution’, 300);
outputPDF = fullfile(outputFolder, ‘output.pdf’); % Define the output PDF file
for i = 1:numTables
% Export the figure to the PDF
exportgraphics(figures{i}, outputPDF, ‘Resolution’, 300, ‘Append’, i > 1, ‘ContentType’, ‘vector’, ‘Padding’, 0.5);
end pdf, size, image, figure, output, merge MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

test one two three four
2025-05-20

test one two three four

Is it possible to make this tiny loop faster?
2025-05-19

Is it possible to make this tiny loop faster?

Solar Wind Battery Hybrid Integration
2025-05-19

Solar Wind Battery Hybrid Integration

Leave a Reply Cancel reply

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

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss