Accessing accumulated in data with index

2 views (last 30 days)
Ashish Mishra
Ashish Mishra on 4 Jul 2021
Edited: dpb on 4 Jul 2021
how an I access accumulated data with index. I make use of [ ] inside for loop for accumation and it works well for single UE, but if I have multiple user, how can I access accumulated data for each variable??
say xyz is a variable for single UE, and its value is different for different value of idx.
xx = [];
for idx = 1:2
xx = [xx xyz];
end
Now, if I have multiple UE, and each's value is changing aross idx, how can I accumulate these values and access them??
  1 Comment
dpb
dpb on 4 Jul 2021
Edited: dpb on 4 Jul 2021
Well, while one can use catenation in that manner, it is very inefficient as it requires a reallocation and copy of the data every iteration through the loop. This may not be show up if the size of the loop and data are small, but if the size gets large, it can (and will) be a real bottleneck to the point of possibly taking minutes or longer to complete a run.
So, the way to solve in general is to preallocate the array and index into it with the new address and data.
As for the Q? as written, it would help if we new what is an UE???
If you're just trying to catenate vectors instead of single elements, then the answer is to use the ":" indexing expression for the subsequent dimensions -- but NB the size of the vector must be the same every pass so that concatenation can be accomplished in that/those direction/s.
x=zeros(N,M); % preallocate the output array
for i=1:N
v=yourfunction(i); % compute the new vector of size(1,M)
x(i,:)=v; % place in its location in output array
end
is the basic idea.
If things are NOT the same size or of the same data class, then use cell arrays.

Sign in to comment.

Answers (0)

Categories

Find more on LTE Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!