Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Row_ID problem

Subject: Row_ID problem

From: audley james

Date: 19 Oct, 2010 07:51:04

Message: 1 of 8

Hello guys,

I have 2 matrices x and y where I want to compare every consecutive 3 rows in x with every consecutive 2 rows in y. So for instance

x =

     2
     4
     7
     1
     4
     8
 
y =

     4
     7
     1
     8


The answer I'd wish to get is the Row_ID_of_x of the missing value when 3 rows in x and 2 rows in y are compared. So

Row_ID_of_x =
                     


                          1
                           
                           
                          5




Row_ID_of_x = 1 is result of comparing x = [2;4;7] and y=[4;7] where the row id


position in matrix 'x' of the missing value 2 is 1.




Row_ID_of_x = 5 is result of comparing x = [1;4;8] and y=[1;8] where the row id


position in matrix 'x' of the missing value 4 is 5.





Please help me out if possible...


audley



                           

Subject: Row_ID problem

From: ImageAnalyst

Date: 19 Oct, 2010 10:16:00

Message: 2 of 8

audley:
One way is to use blockproc() to run a little function. The little
function would call ismember() to see what y are contained in the
chunk of x you're looking at.

Subject: Row_ID problem

From: audley james

Date: 19 Oct, 2010 18:13:04

Message: 3 of 8

Hi,

Please have a look at the code I did below.

Can you please let me if this is what you suggested . I'd like some help if possible to move forward.

thanks again
audley

%-------------------------------------------
clc;
clear all;

x =[ 2
     4
     7
     1
     4
     8]
 
y =[ 4
     7
     1
     8]
 
 
fun = @(block_struct) ismember(x, y)

[row_ID] = blockproc(x,[3 3],fun)
%------------------------------------------------------------

Subject: Row_ID problem

From: audley james

Date: 20 Oct, 2010 02:05:04

Message: 4 of 8

Hi,

Is blockproc the only approach I can take?. Been trying a while and just don't get why it won't work for my situation.

regards
audley

Subject: Row_ID problem

From: ImageAnalyst

Date: 20 Oct, 2010 02:43:40

Message: 5 of 8

No. You could also use nlfilter, colfilt, or just do it brute force
with some nested for loops.

Subject: Row_ID problem

From: audley james

Date: 20 Oct, 2010 03:00:07

Message: 6 of 8

hi imageanalyst,

nlfilter, colfilt seems to use the same function creation approach as blockproc. I am testing to see how they differ from blockproc.

 Can you let me know if the function applied to blockproc code in my 2nd post is along the lines I should be going?

thank you
audley

Subject: Row_ID problem

From: audley james

Date: 20 Oct, 2010 07:42:03

Message: 7 of 8

Hello guys,

I am now trying to do a nested for loop to solve my problem. I have never used a nested for loop before so not sure if my code below is along the correct path.

Can anyone help me out with this post. I've been stuck on this problem for about 2 days now.

take care
audley

%------------------------------------------------------------------------
clc;
clear all;

x =[ 2
     4
     7
     1
     4
     8]
 
y =[ 4
     7
     1
     8]
 

for i= 1:3
    for j = 1:2
    
        [ r , id ] = ismember(x(i,:),y(1,:))
        
    end
end
%------------------------------------------------------------------------

Subject: Row_ID problem

From: Brendan Hannigan

Date: 20 Oct, 2010 14:00:28

Message: 8 of 8

blockproc/nlfilter/colfilt are not really well suited to iterating over 2 different matrices at the same time (although it is possible).

try something like:

===============
num_iterations = numel(x) / 3;
for i = 0:num_iterations-1
   this_section_x = x(3*i+1:3*i+3);
   this_section_y = y(2*i+1:2*i+3);

   ... do something here ...

end
==================

I'll leave the rest for you to finish up, but that's a way for you to iterate over both matrices and investigate the relevant sections of each one.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us