MATLAB: Programming for data processing

dataextract

I have a data set and want to extract rows from the data with same/similar variable name, for which a paricular variable has velues within a range. Example: from a data of temp, humidity, pressure I want to trim out data set which contains humidity and pressure only in the temp range of 30-40 deg C.

Best Answer

You can trim your data by using indexing array idx, as shown below.
% Sample data set
T = array2table(...
[randi([0 50], 100, 1),...
randi([0 100], 100, 1),...
1000+20*rand(100, 1)],...
'VariableNames', {'temp', 'humidity', 'pressure'});
% Trim out humidity and pressure where 30 <= temp <= 40
idx = (30 <= T.temp) & (T.temp <= 40);
Tout = T(idx,{'humidity','pressure'});