Saving data from time loop into 3D matrix

2 visualizaciones (últimos 30 días)
Francesca Paros
Francesca Paros el 30 de Nov. de 2022
Respondida: Divyanshu el 24 de Mzo. de 2023
I am attempting to save my data from my time loop into a 3d matrix but cannot figure it out. I am a beginner and this is the code I have so far however I cannot seem to get it to load into the correct places. My 3d matrix is
data_3d2=NaN(i,3,365);
This is so that for all of my depths, for everyday of the year (but only for the final year), for my variables below z is depth, Tnew is temperature, and Osat is oxygen saturation. I have attempted to use a tracker but it is not working.
if year == total_years
for i=1:N% We need to store the full profile
data_3d2(xdata,1,xcount)=z(i,1);
data_3d2(xdata,2,xcount)=Tnew(i,1);
data_3d2(xdata,3,xcount)=Osat(i,1);
if i == N
xcount = xcount + 1;
end
xdata = xdata + 1;
end
end
I am trying to do this to make a contour

Respuestas (1)

Divyanshu
Divyanshu el 24 de Mzo. de 2023
You have 3 sets of data Z(depth), Tnew(Temperature) & Osat(oxygen saturation). And you want to arrange the data into a 3-d matrix for certain number of samples (N).
Few Assumptions:
  • I have interpreted the 3d matrix as for each sample (1 to N) we have a matrix of size 3*365, where 3 represents the variables Z, Tnew and Osat & 365 represents the days of a year.
  • As N is not clear from the description, I am assuming it to be 10. So now target is to arrange the data of 10 samples.
  • All 3 variables Z, Tnew & Osat are taken as column vectors of 365*1. Here I have taken the data for each sample same and hence have created them as column vectors. But you can modify it as per your requirement.
Here is the sample code for loading the data correctly based on above assumptions:
z = linspace(1,20,365)';
Tnew = linspace(30,45,365)';
Osat = linspace(75,100,365)';
year = 10;
data_3d2 = NaN(10,3,365);
xdata = 1;
xcount = 1;
if year == 10
for k=1:10
xcount = 1;
for i=1:365
data_3d2(xdata,1,xcount)=z(i,1);
data_3d2(xdata,2,xcount)=Tnew(i,1);
data_3d2(xdata,3,xcount)=Osat(i,1);
if i == 365
xdata = xdata + 1;
end
xcount = xcount+1;
end
end
end

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by