Specify output data type of "find" function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm working in simulink and I am running some heavy image processing on a lightweight 32 bit drone. Is there a way to specify the output data type of find? I can convert the row/col indecies to singles after, but it seems like a waste to not set that beforehand. Changing the input matrix type seems to have no effect. Is there something akin to the "like" functionality when using "zeros" or "ones"?
a = rand(5);
class(find(a>.5,1,'first'))
class(find(single(a)>.5,1,'first'))
class(find(single(a>.5),1,'first'))
0 commentaires
Réponse acceptée
dpb
le 22 Oct 2022
" Is there something akin to the "like" functionality [in find]...?"
No.
Everything numeric including indices in MATLAB is a double unless cast to something else...since it will come back as double to begin with and we're only talking a single value , I'd suspect that doing the cast will be more expensive than the cost of the memory. Even if you were to do something like
ix=zero(1,'single'); % preallocate for the index to come later
ix=find(a>0.5,1); % try to assign a double into a single
MATLAB will promote ix to double. Fortran would do t'other way 'round, but MATLAB isn't Fortran.
As you note, the only way if it is imperative to return a single in the output variable is the explicit cast...
ix=single(find(a>0.5,1));
and then it might be better to use uint32 than floating point if the hardware is really limited.
Are we actually running MATLAB here or generating code to run on another processor?
2 commentaires
dpb
le 23 Oct 2022
I've no klew about what the mindrone is, no, but it would depend on what its processor has for an instruction set -- if it doesn't have floating point instruction set, then singles aren't all that efficient, either.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Coder 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!