Efficient assigning of class properties - on multiple levels

2 views (last 30 days)
Hey everyone,
I have the following problem: I got a custom class A that has a property b which is an array of objects of class B. Now each of these objects of class B has a property that is a matrix, let's call it C. I often have to set specific columns of C - many of them, to the same vector. For example, I calculate the vector [1;0;0]. Now, I have to write this vector to, for example, A.b(2).C(:,3), A.b(17).C(:,2), A.b(20).C(:,4) etc. (let's say to 10 places). Right now, I'm doing this via a for-loop.
This works like a charm, but as the b-arrays become bigger (say 1000 items long), this type of operation becomes the dominant factor for the runtime. Writing the vector to all places where it is required takes much longer than actually calculating the vector. (the calculation is quite simple though)
In another place in my code, I was able to get the runtime down significantly by using deal(). I got 2 questions:
- Could I speed up that task by an appropriate use of deal()?
- If yes, how do I do that?
I was trying something like [A.b(vecA).C(:,vecB)] = deal(v) where vecA and vecB contain indices and v is the calculated vector, but apparently using index-vectors on two levels is not OK for MATLAB.
Thanks in advance,
Andreas
  2 Comments
J. Alex Lee
J. Alex Lee on 13 May 2021
not sure what determines the architecture of your classes, but would it make sense to have a simple 3D array as a data backend and have your classes mine that data array?
Andreas Walker
Andreas Walker on 13 May 2021
The classes are already a rather complex manner and changing their architecture is not really an option. Also, the sizes of the matrices C vary.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!