简体   繁体   中英

How to optimize for cycle with cell array - matlab

I've a Matrix A (319 rows × 26 cols) and two vectors that represent an upper_bound (319,1), and a lower_bound (319,1).

My goal is to check if among a set of 26 curves (319 point for each curve) there are some point greater or lower than upper_bound / lower_bound curve in order to exclude a particular set of data if there is at least one point that pass these limits.

Thanks to Shai's suggestions:

>> inBounds = bsxfun(@ge, A, lowerBound) & bsxfun(@le, A, upperBound);   

and using find & accumarray I got a cell array p with all the indices.

Now I'd like to obtain another cell array t with all the original values of A referred to these particular indices.

I've done it with a for cycle, but it needs too much time. Is there a faster way?

Here is the loop:

for gg=1:rows 
    h = genvarname('purge_value', who); 
    eval([h ' = A(gg,p{gg})']); 
end

Don't see what the example code does so I am guessing that you want one of these three:


From your description, I would think it can be simply this:

A(:,inBounds);

This will only keep the series for which all values are in bounds.


If instead, you have a (logical) index p of all values in A that you would like to keep (not series but single values) then you need to decide what to do with the remaining values.

For plotting purposes you could consider doing something like this:

A(~p) = NaN;

However if you have the desire to put it in a cell array, you could consider continuing with something like this:

myArray = cell();
for c = size(A,2):-1:1
 myArray{c} = A(isfinite(A(:,c)),c);
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM