Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:29:14+00:00 2026-06-17T15:29:14+00:00

I have two questions: I have like twelve open figures in MATLAB (already generated

  • 0

I have two questions:

  1. I have like twelve open figures in MATLAB (already generated by another function, figure 1 to 12) and I want to print them all to a file, but also to my printer. How can I write the code for that? I already read about getting handles of the figures but I didn’t really get the meaning of it and how to print them after that.

  2. I wrote a script to import data from many Excel files to MATLAB. The excel files are named so that the only difference is in the the initial part which includes the name/code of the individual person (for whom the information is).

My script looks like this:

Indi1_Sim_T_SFTW1= xlsread('E:\MATLAB\Indi1_Output_SFTW1_6min_100_020812.xls','Indi1_Sim_T_SFTW12')
Indi1_Sim_V_SFTW1= xlsread('E:\MATLAB\Indi1_Output_SFTW1_6min_100_020812.xls','Indi1_Sim_V_SFTW12')

Indi2_Sim_T_SFTW1= xlsread('E:\MATLAB\Indi2_Output_SFTW1_6min_100_020812.xls','Indi2_Sim_T_SFTW12')
Indi2_Sim_V_SFTW1= xlsread('E:\MATLAB\Indi2_Output_SFTW1_6min_100_020812.xls','Indi2_Sim_V_SFTW12')

Indi3_Sim_T_SFTW1= xlsread('E:\MATLAB\Indi3_Output_SFTW1_6min_100_020812.xls','Indi3_Sim_T_SFTW12')
Indi3_Sim_V_SFTW1= xlsread('E:\MATLAB\Indi3_Output_SFTW1_6min_100_020812.xls','Indi3_Sim_V_SFTW12')

Indi4_Sim_T_SFTW1= xlsread('E:\MATLAB\Indi4_Output_SFTW1_6min_100_020812.xls','Indi4_Sim_T_SFTW12')
Indi4_Sim_V_SFTW1= xlsread('E:\MATLAB\Indi4_Output_SFTW1_6min_100_020812.xls','Indi4_Sim_V_SFTW12')

And it goes on for many other individuals.

As you can see, I am repeating the code for each individual. Can I simplify it with a loop function?

P.S: all imported data are numbers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:29:15+00:00Added an answer on June 17, 2026 at 3:29 pm

    Regarding bullet no. 1:

    I have open figures in matlab and I want to print them all to a file, but also to my printer.

    You have the print command for this purpose. Just specify the handle of the figure, for example:

    print(h)                      %// Send figure with handle h to printer
    print(h, '-djpeg', filename)  %// Save figure with handle h to a JPEG file
    

    Regarding bullet no. 2:

    … can I simplify it with a loop function?

    Yes you can. You can do something like this:

    N = 4; %// Number of Excel files
    C = cells(2 * N, 1);
    for k = 1:2 * N
        filename = sprintf('E:\MATLAB\Indi%d_Output_SFTW1_6min_100_020812.xls', k);
        C{k} = xlsread(filename, sprintf('Indi%d_Sim_T_SFTW12', k));
        C{k + 1} = xlsread(filename, sprintf('Indi%d_Sim_T_SFTW12', k));
    end
    

    Now all the data is stored in cell array C.


    Explanation

    I’m planning to store the output of xlsread in a cell array. You have N files and you’re reading data from two worksheets per file, and therefore the cell array C is initialized with 2 * N cells.

    The for loop iterates over each file, and constructs the filename, using the command sprintf and the iteration counter k:

    filename = sprintf('E:\MATLAB\Indi%d_Output_SFTW1_6min_100_020812.xls', k);
    

    The result here is stored in the variable filename, and it is passed to the xlsread command. The sheet names are also constructed using sprintf, and passed directly to the xlsread without being stored in a variable first.

    Q: Why storing the filename in a variable but not the sheetnames?
    A: I’ve decided to store the filename in a variable just because I don’t want to construct it twice, whereas the sheet names are constructed only once, so storing each of them in a variable bears no significance.

    After the loop, the entire data is stored in cell array C. To access the i-th element (cell) in C, use curly braces ({}). For example, to access the second cell, write C{2}.

    Q: Why cell array?
    A: In a cell array each cell can contain data of a different type and length, for instance {2, ‘hello’} is a cell array that contains two cells: one contains the number 2 and the other contains the string “hello”. Since you cannot guarantee that xlsread returns data of the same length, a simple matrix couldn’t be used to store the contents of all files.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions. How can I get the spinner in the figure below
I have two questions. I want to send SMSes from a web-site in PHP
I have two questions: I would like to know if the standards for C++11
I have two questions regarding python libraries: I would like to know if there
I have two questions about Haskell type expression: Question 1 - I would like
I have two questions related to function objects and function pointers, Question : 1
In the course of kernel studying I have two questions: 1) I'd like to
Hi I have two questions about MySQL and QUERIES. First of all i've like
I have two questions: I want to display 6 buttons around an image on
I have two questions per div (page) that look like this: <div id=page5 class=page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.