3D plot from tables in timeline

9 Ansichten (letzte 30 Tage)
Eva R
Eva R am 22 Jun. 2020
Kommentiert: Eva R am 30 Jun. 2020
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 Kommentare
Mohammad Sami
Mohammad Sami am 24 Jun. 2020
Bearbeitet: Mohammad Sami am 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.
Eva R
Eva R am 24 Jun. 2020
Thanks for your patience already!!! :)
So my data has three columns (depth, absorbance, cryptophyta content) and for each row (each depth) the measured parameters of the other two columns.
The dimension that is the same size will then be column number I guess, because all datasets have three columns, Z is kind of a timescale as an add-on, as I am basically just trying to stack the 2D images. I tried saving everything as a matrix, like below but then I get problems with my row number again :(
data1 = readtable ('data1.txt');
data2 = readtable ('data2.txt');
modData1 = table2array(data1);
modData2 = table2array(data2);
matrix = data1;
matrix(:,:,2) = data2;

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mohammad Sami
Mohammad Sami am 24 Jun. 2020
Bearbeitet: Mohammad Sami am 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 Kommentare
Mohammad Sami
Mohammad Sami am 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
Eva R
Eva R am 30 Jun. 2020
Thanks so much! This has worked out great and I was able to create and save the matrix with my interpolated data. I had already sorted the data in a previous step, but I the unique command really helped me.
ArrayData = table2array(finalTable);
% find the index of unique depth values
[~,uniquedepthindex] = unique(ArrayData(:,1));
% use the index to filter out the duplicates
ArrayData = ArrayData(uniquedepthindex,:);
depth = ArrayData(:,1);
crypto = ArrayData(:,2);
LED = ArrayData(:,3);
depthinterval = 0.1;
newdepth = 0:depthinterval:100;
cryptoLED = [crypto LED];
interpData = interp1(depth, cryptoLED, newdepth);
% interpolation of depth data
depthforFinalMatrix = transpose(newdepth);
finalMatrix = [depthforFinalMatrix interpData];
% creation of new matrix with 3 columns: depth, crypto content, LED
Now I am trying to plot it in some 3D matrix, but not sure whether I would use plot3 or surf....

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

darova
darova am 24 Jun. 2020
Can you interpolate your data to make it equal size? Concantenate it and use surf
  1 Kommentar
Eva R
Eva R am 29 Jun. 2020
Thanks, I am trying but currently not successful :D

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by