Effacer les filtres
Effacer les filtres

How can MATLAB's buit-in function give output as class single intead of double?

2 vues (au cours des 30 derniers jours)
JAI PRAKASH
JAI PRAKASH le 25 Août 2018
Modifié(e) : JAI PRAKASH le 26 Août 2018
All matlab function gives output as class double.
e.g.
[I,J] = ind2sub([H W],idx);
it is clear that I & J will be integer type but then also matlab gives values of I & J as class double.
How can get output as class interger 'int16'?
  5 commentaires
Walter Roberson
Walter Roberson le 26 Août 2018
Well, they could be done as uint64.
It would not be unreasonable for MATLAB to support passing in the name of the output type for ind2sub, but it does not currently do so.
JAI PRAKASH
JAI PRAKASH le 26 Août 2018
Modifié(e) : JAI PRAKASH le 26 Août 2018
Thanx @ Walter. for commenting.
I agree with you regarding uint64

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 25 Août 2018
function [I,J]=myind2sub(sz,idx)
I= mod(idx,int16(sz(1)));
J= int16( ceil(idx/sz(2)) );
end
  7 commentaires
Stephen23
Stephen23 le 25 Août 2018
@JAI PRAKASH: then copy ind2sub to your working directories, rename it myind2sub, and make whatever changes you want to the code. Do NOT change the original file.
Matt J
Matt J le 26 Août 2018
Modifié(e) : Matt J le 26 Août 2018
Yes, if you change the built-in ind2sub, you jeopardize the functionality of other Matlab built-ins that rely on its normal behavior.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by