From: Matt Fetterman on 22 Oct 2009 11:22 "the cyclist" <thecyclist(a)gmail.com> wrote in message <hbplbu$6ir$1(a)fred.mathworks.com>... > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hbp7fg$8ve$1(a)fred.mathworks.com>... > > Dear Matt! > > > > > You have 10 churches and 100 members. Each member belongs to 1 church. > > > So the Church structure has the church name, and a list of who belongs to that church and it could have the active index. > > > Church(1).Name='Trinity' > > > Church(1).Members=[1 3 4 6]; > > > Church(1).ActiveIndex=1; > > > Church(2).Name='Quadrinity' > > > Church(2).Members=[2 3 19 50]; > > > Church(2).ActiveIndex=1; > > > Church(3).Name='Pentitude' > > > Church(3).Members=[45 50 55]; > > > Church(3).ActiveIndex=1; > > > ... > > > and the MyChurch array tells us which Church a certain member belongs to. > > > MyChurch(1)=1 > > > MyChurch(2)=1 > > > MyChurch(3)=2 > > > Now if Church(2) closes and all its members shift to Church(3),we could update the Church array as suggested above, Church=Church(ActiveIndex). But then all the indices would shift, so the MyChurch array would have to be updated as well? How would that be done. Thanks, Matt > > > > I have the same problem again and again. I'm using a logical index vector and have to select the n.th TRUE value. Although this works with some FIND statements to switch to index vectors, the speed advantage of the logical indexing disappears. I have not found an efficient solution yet by my own or in the FEX. I think, I'll create a MEX for this task. > > > > Kind regards, Jan > > I have faced some of these challenges as well; for me, they generally arise when I try to use structures kinda like relational databases, which they aren't. > > One thing that springs to mind here is that if the church numbering is subject to change, then that's not a good reference for your MyChurch array. Instead, could you make MyChurch a cell array, referencing Church.Name? > > the cyclist Thanks for comments. Here is a possible way to create a lookup table. poki=[0 1 1 0 1 0 0 0 1 1 0 ]; % array with ones and zeros smoki=zeros(1,length(poki)); % copy array smoki(find(poki))=[1:length(find(poki))]; % create a matrix with labelled find elements Regards Matt
|
Pages: 1 Prev: Symbolic toolbox: Uninitialized variable warnings Next: EzyFit 2.30 |