Although I wrote a big answer saying that you could try using non-scalar structures, the simplest answer may be to keep all of your data in simple numeric arrays: this will work well if your data values are scalar, in which case simple numeric arrays will be the fastest and easiest solution to storing and plotting the data. Simply assign one dimension to represent the days, and the other the hours. Simple.
If these values are not scalar, then you should read on...
You could use a non-scalar structure to store this. A non-scalar structure can be indexed just like any other array in MATLAB, and you could make one axis represent the hours, and another the days: d(days,hours).depth = [...
d(days,hours).temp = [...
Note that these are indices, not values, so they must be positive integer values. You can include fields for each kind of data (e.g. Process type, Flow data, Temperature data, Notes, Units, etc), and the structure itself can be indexed just like any other MATLAB array, here shown with some subscripts day and hour: d(day,hour).depth = [..];
d(day,hour).temp = [..];
d(day,hour).(...
Note that you can even define structure fieldnames dynamically, and that there are many functions that support working on structures and cell arrays, and can access these data easily, and they can also be used in vectorized code (which is something you need to learn about). Non-scalar structures allow very easy access to the data, for example you can obtain all of the depth values in a comma separated list like this:
which means you can create a cell array from all depth values like this:
or concatenate all the depth data matrices like this:
or use them all as inputs to a function like this:
You can retrieve all of the fields and values of for one group of data simply using the index, e.g.:
returns the scalar structure with all of the fields for the ninth day and the 2nd hour, and
gives the corresponding depth value. The index can, just like any other MATLAB array, be logical, subscripts or linear indexing . so you can easily perform operations on a subset of your data like this: myfunction(d(logical_array).temp)
to input into some function the selected temp values. You can also subset a non-scalar structure, just like you would any other array:
assigns the subset of the original structure to the variable B using linear indexing. When you first create the structure, you should consider preallocating it so that it does not keep getting expanded in a loop.
Best Answer