*Function for increasing density and thickness with depth

5 views (last 30 days)
I'm trying to make a function that creates a profile of randomised values (within a range) corresponding to increasing density and thickness of a body with depth. I have a 600 x 2 array with the first column indicating depth (0-600) and the second density (250-900). I've made the first part of my function, implemented the randomisation over a range but now I want to add some functionality wherby as we cycle through each successive row (depth) we select multiple adjacent rows that also get randomised values. So effectively, as we go deeper we select an increasing number of rows for randomisation of density values giving the impression of thicker areas layers being selected. The grpah should look something like I've plotted below but with layers of increasing thickness as we go deeper. I've added what I wrote so far below. I know its probably not efficient so any reccomendations for improving it are welcome.
Base = DP_1989{1:1200,2};
Diff = zeros(1000,1);
for i = 1:length(Base)
Diff(i) = 917 - Base(i);
end
% Pick a random number that generates a random number of ice lenses
rl = round(100.*rand(1,1));
% Index positions for each lens (number between 10:1000)
index = round((1000-10).*rand(rl,1) + 10);
% empty array for new density values
new_density = zeros(1200,1);
% Generate new density values
for i = 1:rl
index(i)
new_density(index(i)) = (917-Base(index(i))).*rand(1,1) + Base(index(i)) ;
end
% Store them somewhere
for i = 1:rl
Base(index(i),2) = new_density(index(i));
end
%Convert original density profile from table to an array
DPtab = table2array(DP_1989(:,(1:2)));
%Insert new density values
for i = 1:rl
DPtab(index(i),2) = Base(index(i),2);
end
% Convert back to table, plot
DP_new = array2table(DPtab);
figure;
x2 = DP_new{:,2};
y2 = DP_new{:,1};
plot(x2,y2)
ylim([0 100])
xlabel('Density(kg m^{⁻3})');
ylabel('Depth(m)');
set(gca, 'YDir','reverse') % Reverses direction of axis so surface is top of y axis

Answers (0)

Community Treasure Hunt

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

Start Hunting!