From: Guangping Zhang on 8 Mar 2010 14:07 Dear All: I'm a new Matlab user, I hope I can get help. I have two matrix in structure S, S. T1 and S.M1, S.T1 is 20000X2, S.M1 is 94X2 matrix. S.M1 was extracted from S.T1, now I need get index from S.T1 to using the loop below and it works fine: for i=1:length(S.M1) ind(i)=val2ind(S.T1(:,1), S.M1(i,1)); end Actually I have 30 pairs of matrix, M1,M2,M3…M30 and T1,T2,T3… in the structure S, I need get the index of M1 from T1, index of M2 from T2,…, so I use another for loop to try get all the index, unfortunately, I got error: for j=1:3 for i=1:length(S.(sprintf('M%j',j))) S.(sprintf('ind%j',j))(i)=val2ind(S.(sprintf('T%j',j))(:,1), S.(sprintf('M%j',j))(:,1)); end end ??? Reference to non-existent field 'T'. Finally, I realize that the serial M file has different length, so maybe the' for loop' is the error source, I try to write it for a while but cannot figure it out. May someone help me? I will really appreciate it.
From: Walter Roberson on 8 Mar 2010 14:30 Guangping Zhang wrote: > Dear All: > I'm a new Matlab user, I hope I can get help. > I have two matrix in structure S, S. T1 and S.M1, S.T1 is 20000X2, S.M1 > is 94X2 matrix. S.M1 was extracted from S.T1, now I need get index from > S.T1 to using the loop below and it works fine: > > for i=1:length(S.M1) > ind(i)=val2ind(S.T1(:,1), S.M1(i,1)); > end > > Actually I have 30 pairs of matrix, M1,M2,M3…M30 and > T1,T2,T3… in the structure S, I need get the index of M1 from T1, > index of M2 from T2,…, so I use another for loop to try get all > the index, unfortunately, I got error: > > for j=1:3 > for i=1:length(S.(sprintf('M%j',j))) > S.(sprintf('ind%j',j))(i)=val2ind(S.(sprintf('T%j',j))(:,1), > S.(sprintf('M%j',j))(:,1)); Those should be %d formats, not %j. As in sprintf('ind%d', j) > end > end > ??? Reference to non-existent field 'T'.
|
Pages: 1 Prev: making executable file from Guide GUI Next: resizing axes |