# Homework Help: Filtering with Matlab

1. Nov 9, 2009

### TFM

1. The problem statement, all variables and given/known data

I have got a table of data, and want to use Matlab to sort this data and filter out some variables. The data was orginally in a FITS format.

2. Relevant equations

N/A

3. The attempt at a solution

Sorry if this is the wrong thread.

I have tried two different versions of code:

hd = (data{12} < rsd);
data_filtered = filter(hd,data,:);

and

idx = (rs < rsd);
data_filtered = data(:,idx);

I need it to filter out all data with a Redshift less then a specified number

Any ideas or thoughts would be really appreciated

Thanks,

TFM

2. Nov 11, 2009

### TFM

Okay, I have found that the data seems to be in a 1x55 table which is the reason I am having trouble filtering it - I get a error message about matrix dimensions.

Any ideas the best way to sort this kind of table?

Many thanks,

TFM

3. Nov 13, 2009

### TFM

Okay I was told Matlab had put my Data in a wierd way so I have now entered the data into a Structure. Does the Filter command still work for Structures, as using the code:

idx = (datastruct.Redshift < rsd);
data_filtered = datastruct(idx)

Gives me a Matrix Error:

??? Index exceeds matrix dimensions.

Error in ==> DensityFunct3 at 12
data_filtered = datastruct(idx)

Any ideas would be greatly appreciated

Many Thanks

TFM

4. Dec 22, 2009

### dsprao

I think the problem is in the index of datastruct, as it is showing. May be the length of data_filtered is not the same as datastruct. It is very common problem occurs in MATLAB. For Example : if H=[1:5]; and then Y=[1:7]; and if you do H=Y(15); then it occurs. Hope it is helpful