How to extract array subset
66 views (last 30 days)
Show older comments
I'm trying to extract an array subset falling into the range from a very large array. The range from Low to High were from user input and the array was loaded from a data file. so the range may not be covered in the data file. the data file is ususally very large, so i don't want to use for loop to cycle through the data set. say for example, I want to pull out the subset from WaveLength that is between Low_WL and High_WL. following is just an example. the range could be anythng like, (500, 4000), (3000, 5000) etc. the data set is a 1X10 cell array with C{3} being the wavelength. I want to save all the fields of cells(C{1} to C{10}) with wavelength falling in range selected to a subset .
pseudo code:
%%wavelength range from user input
WL_low = 2000.0;
WL_High = 2200;
%% declare data structure to store data
DS = struct('mol','name','dt',{{1 2 3 4 5 6 7 8 9 10}});
DS(1:39,1)=DS;
%%Number of molecules selected = 4
for k = 1:4
fid = fopen(sprintf('hit_%d.txt',k));
C = textscan(fid,'%1d%1d%f%f%f%f%f%f%f%f');
%% where C{3} is the cell storing the wavelenth data
%% I want to select the data that falls within the wavelength range and
%% store them to structure if it is not empty
C subset = if C{3} is in range
DS(k).dt = C subset;
end
Any suggestions are highly appreciated! Chong
1 Comment
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!