How to extract array subset

27 visualizzazioni (ultimi 30 giorni)
Chong Tao
Chong Tao il 23 Ago 2013
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 Commento
Azzi Abdelmalek
Azzi Abdelmalek il 23 Ago 2013
This is not clear, give a short example with expected result

Accedi per commentare.

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 23 Ago 2013
WaveLength(WaveLength>=Low_WL & WaveLength<=High_WL)
  5 Commenti
Azzi Abdelmalek
Azzi Abdelmalek il 23 Ago 2013
What do you mean by field?
Chong Tao
Chong Tao il 26 Ago 2013
Modificato: Chong Tao il 26 Ago 2013
for example, I got the dataset from opening a file, and store the dataset to a cell, C{1}, C{2}...C{10} ,with C{3} as the wavelength. I want to select data that falls within the wavelength ranges.
fid = fopen(sprintf('hit_%d.txt',k));
C = textscan(fid,'%1d%1d%f%f%f%f%f%f%f%f');
DS(k).dt = C;
Bellow is some real data,
4 1 3373.09372 1.11E-24 0.6199 0.0698 0.084 1871.2232 0.75 -0.003712
4 5 3373.39637 6.41E-25 0.582 0.0722 0.092 264.2666 0.75 -0.003194
4 1 3373.41688 1.57E-23 0.7 0.0693 0.082 1381.2141 0.75 -0.003972
4 3 3373.45625 2.75E-25 8.244 0.0652 0.076 1629.7286 0.75 -0.004793
4 2 3373.49431 5.44E-25 27.61 0.0726 0.092 1551.4128 0.75 -0.003151
4 1 3373.52899 2.12E-23 0.7031 0.0694 0.083 1311.4242 0.75 -0.003885
so
if I set the range as from 3350 to 3373.4. it should return results as:
4 1 3373.09372 1.11E-24 0.6199 0.0698 0.084 1871.2232 0.75 -0.003712
4 5 3373.39637 6.41E-25 0.582 0.0722 0.092 264.2666 0.75 -0.003194
I hope it is clear. Any suggetions? Thanks again.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by