erase rows and remember string of erased row

Hi everybody, I am new to matlab and am using it to filter financial data. I am encountering a problem regarding the filtering of the data. I have introduced 2 matrices with
[L, CompL, alllow] = xlsread('Corwintest.xlsx',2); and
[H, CompH, allhigh] = xlsread('Corwintest.xlsx',1);.
These matrices contain a column with the company names followed by their High or Low price. What I want to obtain is a allhigh and alllow matrix where the rows with a High smaller than the Low are erased + a collumn that summarizes the companies that have been erased in order for me to use this list as a filter for an other variable ( example volume). This is how it looks like
allhigh =
'U:CBS' [4.3275] [ NaN] [ 4.2500] [ 4.2175] [ 4.2031]
'U:CDI' [8.1250] [ NaN] [ 8.3750] [ 8.2500] [ 8.5000]
'U:CEC' [8.0502] [ NaN] [ 8.0502] [ 7.9514] [ 7.9514]
'U:FUN' [9.9375] [9.8750] [10.1250] [10.1875] [10.6250]
alllow =
'U:CBS' [13.6063] [ NaN] [13.5581] [13.3572] [13.4054]
'U:CDI' [ 8] [ NaN] [ 8.1250] [ 8] [ 8.2500]
'U:CEC' [ 7.8526] [ NaN] [ 7.9020] [ 7.8032] [ 7.8032]
'U:FUN' [ 9.8750] [9.8750] [ 9.8750] [10.1250] [10.1250]
So the code should erase row U:CBS in both 'allhigh' and 'alllow' and store the 'U:CBS' string in order to use it in a filter later on. I hope this is somewhat clear. I know I am asking a lot but I am under pretty big time pressure and could really use some help on this.
Major thanks in advance
Bruno

Answers (1)

allh = cell2mat(allhigh(:,2:end));
alll = cell2mat(alllow(:,2:end));
k = any(allh < alll,2);
allhigh(k,2:end) = {[]};
alllow(k,2:end) = {[]};
ADD
on Bruno comment:
alls = cat(3,allhigh,alllow)
allsmat = cell2mat(alls(:,2:end,:))
k = any(diff(allsmat,1,3)>0,2)
outalls = alls(~k,:,:)
allsve = alls(k,:,:)

2 Comments

Thanks a lot!!!. But do you have any ideas on how I can get an output where a new matrix of 3x6(first row erased)is created instead of 4x6?
I seem to be doing something wrong.
Matlab gives following error:
??? Error using ==> cat
CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 131
m = cat(1,c{:});
Error in ==> filter_HL at 10
allsmat = cell2mat(alls(:,2:end,:))
Thanks again

This question is closed.

Asked:

on 12 Mar 2012

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!