3D plot from tables in timeline
6 views (last 30 days)
Show older comments
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!! :)
7 Comments
Mohammad Sami
on 24 Jun 2020
Edited: Mohammad Sami
on 24 Jun 2020
What is the size of the data you are loading. What do the rows and columns correspond to ?
For plot3, the X,Y,Z values must satisy either of these properties for the function to work
Vector of same length or
Specify at least one of X, Y, or Z as a matrix, and the others as vectors. Each of X, Y, and Z must have at least one dimension that is same size. For best results, specify all vectors of the same shape and all matrices of the same shape.
Accepted Answer
Mohammad Sami
on 24 Jun 2020
Edited: Mohammad Sami
on 24 Jun 2020
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.
4 Comments
Mohammad Sami
on 29 Jun 2020
Also if there are multiple entries for the same depth, you can also get the above error.
In that case you can use unique to remove the duplicate depth entries.
% find the index of unique depth values
[~,uniquedepthindex] = unique(ArrayData(:,1));
% use the index to filter out the duplicates
ArrayData = ArrayData(uniquedepthindex,:);
% continue with interpolation
More Answers (1)
darova
on 24 Jun 2020
Can you interpolate your data to make it equal size? Concantenate it and use surf
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!