Matlab: Appending numbers as strings to a variable name

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 9K views
Meteochick
Messages
2
Reaction score
0
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!
 
Physics news on Phys.org
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:
That makes sense! Thanks a lot, I'll give it a try!