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

조회 수: 2 (최근 30일)
JAI PRAKASH
JAI PRAKASH 2018년 8월 25일
편집: JAI PRAKASH 2018년 8월 26일
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
Walter Roberson
Walter Roberson 2018년 8월 26일
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 2018년 8월 26일
편집: JAI PRAKASH 2018년 8월 26일
Thanx @ Walter. for commenting.
I agree with you regarding uint64

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2018년 8월 25일
function [I,J]=myind2sub(sz,idx)
I= mod(idx,int16(sz(1)));
J= int16( ceil(idx/sz(2)) );
end
  댓글 수: 7
Stephen23
Stephen23 2018년 8월 25일
@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 2018년 8월 26일
편집: Matt J 2018년 8월 26일
Yes, if you change the built-in ind2sub, you jeopardize the functionality of other Matlab built-ins that rely on its normal behavior.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by