MATLAB Matlab: Appending numbers as strings to a variable name

AI Thread Summary
Appending a number as a string to variable names in MATLAB is not feasible, but an effective alternative is to use an array of structures. Instead of creating separate variable names like Volume1, Volume2, etc., you can define a single structure array, such as Volume(1), Volume(2), and so on. This allows for dynamic handling of varying numbers of data volumes without prior knowledge of their count. Each structure can contain fields for elevation angles, ranges, velocity data, and reflectivity data, streamlining data management for radar files. This approach simplifies the coding process and enhances organization when dealing with multiple data volumes.
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!
 
Back
Top