I have many large arrays of temperature and pressure data, each contained in cells. I'd like to find the temperature values at each corresponding pressure index when the pressure value is closest to 850. Pressure is stored in [distance x height] and the resulting temperature arrays need to be [1 x distance] - as in, temperature needs to pull only one number from each pressure column.
I've tried finding the indices of each pressure array where the values are between 840 and 860:
for k = 1:length(hdfFiles)
airTemp850{k} = airTemp{k}(pressure{k} > 840. & pressure{k} < 860.);
end
but sometimes there are no pressure values between these numbers. If I expand the range, it sometimes covers more than one pressure column and I end up with too many values in the temperature array.
I also tried finding the closest pressure values to 850 but this only finds the one value in the entire pressure array closest to 850.
for k = 1:length(hdfFiles)
val = 850;
diffVal{k} = abs(minus(pressure{k}(:),val));
[idx idx] = min(diffVal{k}) % index of closest value to 850
closest{k} = pressure{k}(idx{k});
end
What I'd like is for matlab to read through every row of pressure, find the value closest to 850, and pull out the corresponding temperature value. Any help is greatly appreciated. Thanks!