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:
array

Subject: array

From: tawfik tawfik

Date: 21 Feb, 2011 20:46:04

Message: 1 of 9

Hello,

i have some vectors :
T[1]= [ 1 2 3]
T[2]= [2 3]
T[3]= [1 2 3]
T[4]= [ 1 2]
T[5]= [ 1 3]

and i must have this result :

T[1,1]= [ 3 4 5]
T[1,2]= [2 3 4]
T[1,3]= [2 3 5]
.
.
.
.
ect

which :
T[1,1] containt index of table that containt element 1, so we have table 3 , 4 ,5 that contain element 1.
T[1,2] containt index of table that containt element 2, so we have table 2 , 3 ,4 that contain element 1.
...........ect

i am blocked and i dont know how i can devlopp my code. thank you

Subject: array

From: tawfik tawfik

Date: 22 Feb, 2011 03:54:20

Message: 2 of 9

i am blocked...can anybody help me plz?

Subject: array

From: tawfik tawfik

Date: 25 Feb, 2011 19:25:10

Message: 3 of 9

i tried this code for 2 vectors:

tableau1 = [1,2,3];
tableau2 = [2,3];
res=[];
k=1;
for i = 1 : 3
    for j = 1 : 2
        if tableau1(i)==tableau2(j)
            res(k)= tableau1(i)
            disp(res(k))
            k=k+1;
            break
        end
    end
end

but i need to stock the result in vector with indice ij to refer tableau_i and element j

can somone help me plz?

Subject: array

From: dpb

Date: 25 Feb, 2011 19:48:33

Message: 4 of 9

On 2/25/2011 1:25 PM, tawfik tawfik wrote:
> i tried this code for 2 vectors:
>
> tableau1 = [1,2,3];
> tableau2 = [2,3];
> res=[];
> k=1;
> for i = 1 : 3
     for j = 1 : 2
> if tableau1(i)==tableau2(j)
> res(k)= tableau1(i)
> disp(res(k))
> k=k+1;
> break
> end
> end
> end
>
> but i need to stock the result in vector with indice ij to refer
> tableau_i and element j
>
> can somone help me plz?

 >> t1=1:3,t2=2:3;
 >> idx=intersect(t1,t2)
idx =
      2 3
 >> res=t1(idx)
res =
      2 3
 >>

--

Subject: array

From: tawfik tawfik

Date: 25 Feb, 2011 20:19:06

Message: 5 of 9

hello

thank you very much, but i want get a result like : if i put a vector table_i and i search a element table_i(k) in the other vector table_j, i must have a vector called as
table[table_i(k)j]

for example :

T[1]= [ 1 2 3];
T[2]= [2 3];
T[3]= [1 2 3];
T[4]= [ 1 2];
T[5]= [ 1 3];
 

i must get as result :

T[1,1]= [ 3 4 5]
T[1,2]= [2 3 4]
T[1,3]= [2 3 5]
........
....... ect

a vector res must have a index

Subject: array

From: tawfik tawfik

Date: 26 Feb, 2011 01:35:14

Message: 6 of 9

its a little hard...i didnt find any comand in matlab that can index vectors

Subject: array

From: Nasser M. Abbasi

Date: 26 Feb, 2011 01:52:39

Message: 7 of 9

On 2/25/2011 5:35 PM, tawfik tawfik wrote:

> its a little hard...i didnt find any comand in matlab that can index vectors

That is correct.

It impossible to index a vector in Matlab. One of Matlab's most
series design issues, and you discovered it. Well done.

In Matlab, one can not write

A(i)

Where A is a vector.

Try Java, I think in Java you can do that.

--Nasser

Subject: array

From: tawfik tawfik

Date: 7 Mar, 2011 05:28:04

Message: 8 of 9

hello

thank you for reply, i tried this code to compare first element :

x{1,1}=[1 2 3];
x{2,1}=[2 3];
x{3,1}=[1 2 3];
x{4,1}=[1 2];
x{5,1}=[1 3];
p=1;
for k=1:length(x{1})
    for j=1:length(x{1})
      elt_tofind=x{1}(j);
           for i=2:length(x)
              if ~isempty(find(elt_tofind==x{i,1}))
              x{k,3}(p)=i;
              p=p+1;
              end
          end
     end
end

but i get
    3 4 5 2 3 4 2 3 5
i want to get as result
 3 4 5
2 3 4
 2 3 5

Subject: array

From: Bruno Luong

Date: 7 Mar, 2011 09:29:31

Message: 9 of 9

x{1,1}=[1 2 3];
x{2,1}=[2 3];
x{3,1}=[1 2 3];
x{4,1}=[1 2];
x{5,1}=[1 3];

% Try this:

m = size(x,1);
loc = arrayfun(@(row) row+zeros(size(x{row,1})), (1:m).', 'unif', 0);
n = max(cellfun('length',x));
z = cell(m,n);
for r=1:m
    xr = x{r,1};
    others = setdiff(1:m, r);
    y = cat(2,x{others}).';
    l = cat(2,loc{others}).';
    [f i] = ismember(y,xr);
    a = accumarray(i(f), l(f), [], @(a) {sort(a).'});
    z(r, 1:length(a)) = a.';
end

z{1,:}

% Bruno

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