필터 지우기
필터 지우기

How to extract array subset

조회 수: 76 (최근 30일)
Chong Tao
Chong Tao 2013년 8월 23일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 23일
This is not clear, give a short example with expected result

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 23일
WaveLength(WaveLength>=Low_WL & WaveLength<=High_WL)
  댓글 수: 5
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 23일
What do you mean by field?
Chong Tao
Chong Tao 2013년 8월 26일
편집: Chong Tao 2013년 8월 26일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by