MATLAB: 3D plot from tables in timeline

3d plottimescale data

Hello!
I am trying to plot my data (contains water depth and absorbance at 2 different wavelengths for each measured depth) into a 3D plot. I have pre-procressed the data so all datasets (approx 100/year) contain the same variables and the same number of columns in a table, but the number of rows sometimes varies (I don't have equal numbers of depth measurements). I would like to plot my data into a 3D plot so all data from one year can be in one surface-3D plot to visualize the development over one year.
I have tried putting all my data into a 3D matrix and then plotting it, but I have multiple problems: I tried using table2array and then creating a 3D array, but the different row numbers keep giving me problems. I tried using zeros() and then an array overlay with all smaller tables, but 1) I don't know which one is my biggest dataset and 2) I don't want to do this manually/ I would like to use some kind of loop to first fill the 'empty' rows with zeros and then put everything together in one 3D matrix and then plot it into a 3D plot.
Can anybody help here?
Thanks!! 🙂

Best Answer

Based on my understanding each file 'data1.txt' is from one particular time
Different number of rows means, you are missing certain depth values.
One option would be to use interpolation to standardise your data into a standard format.
Assuming you have depth measurement from 0 to 100m, you can interpolate to a desired interval
function out = read_data(filename)
data = readtable (filename);
modData = table2array(data);
depthinterval = 0.1; % 0.1m
newdepth = 0:depthinterval:100;
olddepth = modData(:,1); % first column = depth
olddata = modData(:,2:3) % data columns
newdata = interp1(olddept,olddata,newdepth);
out = [newdepth newdata];
end
The output will then have the same number or rows, so that you can stack them easily.
Related Question