From: radar on 2 May 2010 17:02 How do I store results generated in a loop when they are of different lengths? for i=1:390 find(mat(:,4)==i); end; I'm searching a matrix for values in the 4th column. Because of the data therein, find will return a different number of indices for each value of i (find i==1 returns 100 indicies, i == 2 returns 75, etc) I need to store those results as they are collected, and refer back to them by the value of i as an index. I'm a newbie and would appreciate your help. Thanks.
From: Walter Roberson on 2 May 2010 22:03 radar wrote: > How do I store results generated in a loop when they are of different lengths? > > for i=1:390 > find(mat(:,4)==i); > end; Use cell arrays. foundindices{i} = find(mat(:,4)) == i; Noitice the {} instead of () .
From: TideMan on 2 May 2010 22:04 On May 3, 1:02 pm, radar <lcar...(a)tds.net> wrote: > How do I store results generated in a loop when they are of different lengths? > > for i=1:390 > find(mat(:,4)==i); > end; > > I'm searching a matrix for values in the 4th column. > Because of the data therein, find will return a different number of indices for each value of i > (find i==1 returns 100 indicies, i == 2 returns 75, etc) > > I need to store those results as they are collected, and refer back to them by the value of i as an index. > > I'm a newbie and would appreciate your help. Thanks. You need to use a cell array: c{i}=find(mat(:,4)==i); Note the curly brackets. BTW, some gratuitous advice: Don't use i or j as indices. By default, Matlab treats them as sqrt(-1). Use symbols like k, m, n, ia, etc.
From: radar on 2 May 2010 18:28 thank you Walter
From: radar on 2 May 2010 18:29 thank you Derek on both counts
|
Pages: 1 Prev: From Workspace and Simulink sample time Next: SOM Toolbox for Classification |