File Exchange Pick of the Week

October 24th, 2008

Displaying Structures

Jiro's pick this week is ANY2CSV by Felix Zoergiebel.

I use structures quite often. It allows me to store heterogeneous information in one variable, and I can have structures within structures as well. Sometimes, I go crazy and make many levels of hierarchy to organize my information.

Let's take a look at this data.

load data
whos
  Name      Size            Bytes  Class     Attributes

  a         4x1              2704  struct              

This is a structure that contains information from a series of stress tests. I can dig into the structure to see its contents...

a(1)
ans = 
     TestName: 'Stress Test One'
    Condition: 'fast'
         Test: [2x1 struct]
a(1).Test(1)
ans = 
     Date: 'May 3'
    Score: 89

But sometimes, I just want to view everything at once. ANY2CSV allows you to do just that. It flattens the structure and either displays it on the screen or saves it as a CSV file.

any2csv(a, ',', 0, 'a.csv');

Now, I have a summary of the data stored in the structure.

Very nice! I also want to thank Felix for his quick response to my enhancement request. I asked him whether the fields of the structure could be displayed vertically, rather than horizontally, and he updated the submission in a timely manner.

Comments?

Data visualizations don't always come in the form of graphs. We'd love to hear about other interesting ways of viewing information. Tell us about it here.


Get the MATLAB code

Published with MATLAB® 7.7

2 Responses to “Displaying Structures”

  1. Peterslove replied on :

    Hi,
    I have a question for you guys. i ll like to program a simple monte carlo simulation in matlab exclusively showing hardening of a beam. i.e A beam of light incident on a slab of water. To compare the incident and the transmitted spectra to see the effect of hhardening. Can some one help me out there with the matlab codes. Not c or c++

  2. jiro replied on :

    Peterslove,

    I think this is off-topic for this blog (unless you were mistaking MATLAB structures with mechanical structures).

    You should post this question on the CSSM newsgroup, but you may need to rephrase your question a bit. You will have a better chance of getting a response when you ask questions on specific MATLAB tasks, rather than a request for MATLAB code to solve a general problem.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?
  • Doug: @Lucy I think this is what you seek to move a line with the mouse in MATLAB. http://blogs.math...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.