convert complex number string to corresponding character string
13 ビュー (過去 30 日間)
古いコメントを表示
hey I just want to convert a large complex number string into its corresponding character string. My code is:
u=w+zne;
h=double(u); %I used double() because 'u' is a symbolic variable.
enc=num2str(h);
If zne=(1e+2+22e+3i) then num2str works but if I increases the value of zne like (123e+3+23e+4i) then it returns result in number string form as [1.234104e+061.234105e+061.234044e+061.234116e+0...] I require result in character form as [ansdfff...].
Please help me...
2 件のコメント
Prannay Jain
2016 年 11 月 14 日
What are the values of u, w, h and enc in your case? When I used num2str(123e+3+23e+4i) it worked fine. I need to check other values to reproduce the issue.
採用された回答
Walter Roberson
2016 年 11 月 16 日
The result of your fscanf is system dependent, and depends upon your region settings and some environment variables in order to know how the bytes in the file are going to be converted to characters. I recommend that you supply the encoding parameter to the fopen call, such as 'UTF-8' or 'ISO8896-1'
Without that knowledge it is hard for us to talk about what is happening to the bytes.
You add 232e+5 to the imaginary component of what you have on input. That value exceeds 65536 which is the largest representable character position in MATLAB.
1 件のコメント
Walter Roberson
2016 年 11 月 16 日
You are using the %c format specifier. That specifier is for taking non-negative integer character numbers and marking them as characters, like position #48 is '0', which is something that does not involve any formatting at all. Your values are outside the range of integers from 0 to 65535, so your values are being treated as if a %e format had been written, which is what fprintf() and related routines do with values out of range for the given format -- use %e format instead.
You can format an imaginary number as decimal values by using one of the numeric formats %e, %f, %g, applied to the real and imaginary portions. For example,
final = sprintf('%g%+gi', real(res), imag(res))
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!