CHAR AND DOUBLE FUNCTION IN MATLAB

5 ビュー (過去 30 日間)
Raza
Raza 2014 年 10 月 1 日
コメント済み: José-Luis 2014 年 10 月 1 日
How to see the function coding in matlab that uses char to convert decimal valuein to respective ascii character and uses double to convert character into respective ascii decimal value

回答 (1 件)

Guillaume
Guillaume 2014 年 10 月 1 日
You can't, it's a built-in function of matlab, not an m-file. Most likely it's written in C, and the implementation is trivial in C, it's just a cast.
  6 件のコメント
Guillaume
Guillaume 2014 年 10 月 1 日
編集済み: Guillaume 2014 年 10 月 1 日
The OP asked about 'double to convert into respective ascii decimal value', that is in matlab:
d = 65; %is a double in matlab
c = char(d);
That is a simple cast in C:
double d = 65;
char c = (char)d; //c == 'A';
And actually, the reverse doesn't even need a cast. It's just an implicit conversion:
char c = 'A';
double d = c; //d == 65.0
José-Luis
José-Luis 2014 年 10 月 1 日
Maybe. I did not interpret the OP's original question like that though, so we might be arguing over nothing until he clarifies.
It might be good to clarify, as you sort of did, that char is not really an absolute type, as its size can change depending on the implementation. It is an integer in disguise. If you take it like that, then yes, it is trivial (in application if not in implementation).
If not, then my comment remains valid.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by