2 views (last 30 days)

Show older comments

Hi,

I have a matrix, A. Each column is a set of consecutive numbers of different lengths, padded with nan because I extracted from a cell array. I have a column vector, B. The numbers in both are indices of curves I am trying to define, and they are both in increasing order. I want to make the values of B the starting points of the consecutive numbers in A, for each column.

I want to go through each column of A and find where there is also a point from B, and then get rid of all the values in that column of A below that overlapping point. I am trying to write a 'for' loop with 'ismember' but I either get error messages or it doesn't actually do anything. The output would be either a cell array or a matrix.

%for example

A=[ 1 7 20

2 8 21

3 9 22

4 10 23

nan 11 24

nan nan 25

nan nan 26 ...]

B=[2 7 8 22]

C=[ 2 7 22

3 8 23

4 9 24

nan 10 25

nan 11 26 ...]

I've tried the for loop to find where A and B overlap but I can't even get that far

for i=1:size(A,2)

C(i)=ismember(B(:,i),A)

end

Please help either with this method or any one that works!

Thanks

Mrutyunjaya Hiremath
on 24 Apr 2020

Code is Not optimized, but works fine

maxRow = 1;

for i=1:size(A,2)

BIndex = ismember(B,A(:,i));

BIndex = find(BIndex, 1, 'first');

indexA = find(A(:,i) == B(BIndex));

D = A(indexA:end,i);

E{i} = D(~isnan(D));

if (maxRow < length(E{i}))

maxRow = length(E{i});

end

end

C = NaN(maxRow,size(E,2));

for i = 1:size(E,2)

C(1:length(E{i}),i) = E{i};

end

disp(C)

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

Start Hunting!