Prev: Stand alone application (gui) crashes with unexpected java error
Next: pcmcia parallel port emulator
From: Jonas Baumann on 7 Jan 2010 08:56 When doing simulation I often end uf with a data structures along the line of: MyData: Value1: Value: 1x10000 Time: 1x10000 Value2: Value: 1x10000 Time: 1x10000 .. .. .. ValueN: Value: 1x10000 Time: 1x10000 What I often need to do is extract the same time window out of all values, i.e. from vectors only indizes 1000:2000. Is there a quick solution to this for large N (10-100)?
From: Andy on 7 Jan 2010 09:06 "Jonas Baumann" <baumann.jonas(a)gmail.com> wrote in message <hi4p5i$8vv$1(a)fred.mathworks.com>... > When doing simulation I often end uf with a data structures along the line of: > > MyData: > Value1: > Value: 1x10000 > Time: 1x10000 > Value2: > Value: 1x10000 > Time: 1x10000 > . > . > . > ValueN: > Value: 1x10000 > Time: 1x10000 > > What I often need to do is extract the same time window out of all values, i.e. from vectors only indizes 1000:2000. > Is there a quick solution to this for large N (10-100)? If this is your goal, then you should form a structure array from the beginning. That is, instead of MyData with fields Value1, Value2, etc., have MyData be a structure array with MyData(1) storing the value and time for Value1, MyData(2) storing value and time for Value2, and so on. Then I think (I'm not at MATLAB at the moment) to pull out the time, you would just say [MyData(:).Time].
From: Jonas Baumann on 7 Jan 2010 09:15 "Andy " <theorigamist(a)gmail.com> wrote in message <hi4poq$ob8$1(a)fred.mathworks.com>... > "Jonas Baumann" <baumann.jonas(a)gmail.com> wrote in message <hi4p5i$8vv$1(a)fred.mathworks.com>... > > When doing simulation I often end uf with a data structures along the line of: > > > > MyData: > > Value1: > > Value: 1x10000 > > Time: 1x10000 > > Value2: > > Value: 1x10000 > > Time: 1x10000 > > . > > . > > . > > ValueN: > > Value: 1x10000 > > Time: 1x10000 > > > > What I often need to do is extract the same time window out of all values, i.e. from vectors only indizes 1000:2000. > > Is there a quick solution to this for large N (10-100)? > > If this is your goal, then you should form a structure array from the beginning. That is, instead of MyData with fields Value1, Value2, etc., have MyData be a structure array with MyData(1) storing the value and time for Value1, MyData(2) storing value and time for Value2, and so on. Then I think (I'm not at MATLAB at the moment) to pull out the time, you would just say [MyData(:).Time]. Thanks for the reply. This would work, correcto. However, I often prefer using substructeres the way I described it because you immediatly know which subvector has which meaning. Numbering them is often easier, but for me, not always. Any other solutions?
From: Andy on 7 Jan 2010 09:39 But ValueN is just numbering as well. In any case, your problem can be easily solved in a loop if you need to keep your structure like this: % generating some data for ix=1:100 s.(['v' num2str(ix)]).val=ix; s.(['v' num2str(ix)]).time=rand; end % extracting the times T=zeros(1,100); for jx=1:100 T(jx)=s.(['v' num2str(jx)]).time; end You'll need to slightly modify this to extract time vectors instead of single numbers.
From: Jan Simon on 7 Jan 2010 10:24 Dear Jonas! > Value1: > Value: 1x10000 > Time: 1x10000 > Value2: > Value: 1x10000 > Time: 1x10000 > ... > ValueN: > Value: 1x10000 > Time: 1x10000 You have to decide if you want descriptive fieldnames and substructs *or* fast access to certain subvectors of the data. Nevertheless, you could copy(!) all subvectors together to a big matrix: S.a.time = rand(1, 10); S.b.time = rand(1, 10); S.b.time = rand(1, 10); SCell = struct2cell(S); SArray = cat(1, S{:}); TimeMatrix = cat(1, SArray.time) This creates several copies of your data, so it may polute your memory. Some CLEAR command may help. Good luck, Jan
|
Next
|
Last
Pages: 1 2 Prev: Stand alone application (gui) crashes with unexpected java error Next: pcmcia parallel port emulator |