I have measurement data from four sensors, each gives current speed at a given water depth (d) and time (t). Below is the matrix dimension of these four current measurements:
cs1 = [d1 x t1]; cs2 = [d2 x t2]; cs3 = [d3 x t3]; cs4 = [d4 x t4]
The water depth arraysd1, d2, d3, d4
are unique values, but their range overlaps. For example, d1=5:4:141
and d2=72:2:200
. Time arrays t1,t2,t3,t4
also have different start and end points with different timesteps.
I need to create a combined matrix cs
which includes data from all four sensors. For this I have created a NaN
matrix as:
t = unique([t1;t2;t3;t4]);
d = unique([d1 d2 d3 d4]);
cs = NaN(length(d),length(t));
% Populaitng data from 1st sensor
for i=1:length(d1)
for j=1:length(t1)
cs(d==d1(i) & t==t1(j))=cs1(i,j);
end
end
I am using a for
loop to populate the cs
matrix for one instrument data at a time. This way is quite inefficient since both depth and time array sizes are quite large.
Is there a quicker method to fill the cs
matrix without running a for
loop for each intrument?