- 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.
Saving data from time loop into 3D matrix
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Divyanshu
on 24 Mar 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:
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!