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 8486311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:54:33+00:00 2026-06-10T20:54:33+00:00

So I have a for-loop, and at every iteration, I would like to display

  • 0

So I have a for-loop, and at every iteration, I would like to display formatted text, along with some numbers. Normally one could use disp or fprintf I suppose, but what I want to do, is have the same part of the command window output the text/numbers, just overwriting the old output.

How might I be able to do that? I have seen it in some other programs so I know it is possible, but not how.

As an example, lets say on the first iteration of a for-loop, I want this to be output on the command prompt:

>> Measurement1 : 0.33 0.23 0.34 -32.32
   Measurement2 : 433.2
   Text Stuff   : 'The cat who ate the rat'

Now, on the second iteration of the loop, I DONT want a new line or lines, I simply want the old numbers and old text to be replaced, in the same place on the command window. So on teh second iteration, I might get this:

>> Measurement1 : -132.3 32.1 32.23 -320.32
   Measurement2 :  3.2
   Text Stuff   : 'The dog who ate the cat'

Thanks

  • 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-10T20:54:35+00:00Added an answer on June 10, 2026 at 8:54 pm

    Here’s an example of what you’re looking for:

    %# Generate the data
    Measurement1 = {[0.33 0.23 0.34 -32.32]; [-132.3 32.1 32.23 -320.32]};
    Measurement2 = {433.2; 3.2};
    TextStuff = {'The cat who ate the rat'; 'The dog who ate the cat'};
    s = cell2struct([Measurement1, Measurement2, TextStuff], ...
        {'Measurement1', 'Measurement2', 'TextStuff'}, 2); 
    
    str_format = @(tag, value)sprintf('%s:%s', tag, value);
    
    %# Iterate over the data and print it on the same figure
    figure
    for i = 1:length(s)
    
        %# Clear the figure
        clf, set(gcf, 'color', 'white'), axis off
    
        %# Output the data
        text(0, 1, str_format('Measurement1', num2str(s(i).Measurement1)));
        text(0, 0.9, str_format('Measurement2', num2str(s(i).Measurement2)));
        text(0, 0.8, str_format('TextStuff', s(i).TextStuff))
    
        %# Wait until the uses press a key
        pause
    end
    

    Note that pause forces you to press a key before the next iteration is executed. I’ve put it there so that you can get the chance see the figure in each iteration.

    P.S
    Based on this answer (to another question of yours), you can also output LaTex equations.


    EDIT – some more explanation:

    cell2struct is a function that converts a cell array to structure array. In your case, you have Measurement1, Measurement2 and TextStuff, each being a cell array holding data about different fields.
    All cell arrays are unified into one array of cell arrays: [Measurement1, Measurement2, TextStuff]. cell2struct takes each row from each cell array and forms a struct, the result being stored as an array of structs, like so:

    s = 
    
    2x1 struct array with fields:
        Measurement1
        Measurement2
        TextStuff
    

    You can extract the first set of values using s(1), the second using s(2), and so on.
    For instance s(1).TextStuff gives you 'The cat who ate the rat'.

    I suggest you that type s in the MATLAB command prompt to see its contents.

    The helper function str_format is an anonymous function that I’ve created to format the output string for each field. Its input arguments are tag (the field name string) and value (field value string), which are concatenated together using the sprintf command, similar to the sprintf function in C/C++.

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

Sidebar

Related Questions

I have loop and each iteration of Hash looks like this: [1, {:clid=>1, :nvz=>4,
I have a very long loop, and I would like to check the status
I have a Foreach loop and every iteration puts the record into a system.
I have a loop which basically calls this every few seconds (after the timeout):
I have this PHP code in a loop for every post on the admin
I have the code below and I want to loop this every 5 seconds.
I have a recordset loop that creates a table, and every 9 items it
I'm pretty new to jQuery/JS. But I have loop in jQuery where I would
I have this loop method to display a ViewPager and I set an OnClickListener
I have a loop that enters each non-empty text field into a database: foreach

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.