Assigning values to the array of Enumeration Class seems to be very slow
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I met this problem when parsing a gps log.
I made an Enumeration Class GpsState as follows.
classdef GpsState
enumeration
Lost
Single
RTD
RTK_Float
RTK_Fix
end
end
Then I created an array of GpsState to record all the states of the log. The process was painfully slow.
Finally, I found out what the problem was caused by the assign of Enumeration Class array.
I simplified the code as follows, the process takes about 4.6s.
tic
test_num = 1e5;
gps_state = repmat(GpsState.Lost,test_num,1);
for ii = 1:test_num
gps_state(ii) = GpsState.RTK_Fix;
end
toc
Is there any problem with my usage mode of Enumeration Class?
Thanks for your reading.
0 commentaires
Réponses (1)
Steven Lord
le 20 Jan 2020
Why are you initializing all the elements in gps_state to GpsState.Lost in one call them immediately overwriting them with GpsState.RTK_Fix?
If you oversimplified your problem, and you wanted say) to only overwrite certain elements of gps_state, there's no need for a for loop here. Just overwrite them in one fell swoop, something like this untested code.
test_num = 1e5;
gps_state = repmat(GpsState.Lost, test_num, 1);
OneThousandRandomPoints = randperm(test_num, 1000);
gps_state(OneThousandRandomPoints) = GpsState.RTK_Fix; % scalar expansion
Voir également
Catégories
En savoir plus sur Enumerations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!