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
Here’s an example of what you’re looking for:
Note that
pauseforces 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:
cell2structis a function that converts a cell array to structure array. In your case, you haveMeasurement1,Measurement2andTextStuff, each being a cell array holding data about different fields.All cell arrays are unified into one array of cell arrays:
[Measurement1, Measurement2, TextStuff].cell2structtakes each row from each cell array and forms a struct, the result being stored as an array of structs, like so:You can extract the first set of values using
s(1), the second usings(2), and so on.For instance
s(1).TextStuffgives you'The cat who ate the rat'.I suggest you that type
sin the MATLAB command prompt to see its contents.The helper function
str_formatis an anonymous function that I’ve created to format the output string for each field. Its input arguments aretag(the field name string) andvalue(field value string), which are concatenated together using thesprintfcommand, similar to thesprintffunction in C/C++.