Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: Appending numbers as strings to a variable name

  1. Jul 12, 2010 #1
    Hello,

    I am wondering if it is possible to append a number as a string to the end of a variable name in Matlab? I am working with radar data and want to create structures for each volume of data, but I do not know how many volumes are contained in each file, and I have so many files I do not want to have to go through and count each of them! Here's an explanation of my data and what I'm trying to do.

    Velocity and reflectivity data are collected at a specific number of range points, over a series of azimuth angles which is repeated over a known number of elevation angles. The grouping of range, azimuth, elevation is what I am calling a volume. Each data file I am dealing with contains 5 minutes worth of data, but the number of volumes collected is not constant because the number of elevations or azimuth angles can change from file to file. I want to create structures for each of the volumes within the file so that I have something like: Volume1 =struct('El1',{Elevation_Angles},'Range1',{Ranges},'V1',{Velocity_data},'Ref1',{Reflectivity_data}, Volume2=(The same thing except for the next volume)...

    Is it possible to have some representation of the count of the volumes and append to the variable name 'Volume' so that I can create these different structures without needing prior knowledge of the number of volumes? (i.e. something like Volume($count), as it would be in a c-shell script?) OR, is there a better way of doing what I'm trying to do here without needing separate structures?

    Thanks so much!
     
  2. jcsd
  3. Jul 14, 2010 #2
    You can use an array of structures. Like
    Volume(1) = struct('El', Elevation_Angles, 'Range', Ranges, 'V', Velocity_data, 'Ref', Reflectivity_data)
    Volume(2) = struct('El', Elevation_Angles, 'Range', Ranges, 'V', Velocity_data, 'Ref', Reflectivity_data)

    etc
    Basically, just put the number in parenthesis after Volume instead of trying to append it as a string.
     
    Last edited: Jul 14, 2010
  4. Jul 14, 2010 #3
    That makes sense! Thanks a lot, I'll give it a try!
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook