フィルターのクリア

How to convert a char array into a double array?

91 ビュー (過去 30 日間)
HJ Jay
HJ Jay 2014 年 8 月 3 日
コメント済み: HJ Jay 2014 年 8 月 3 日
I have a character array (68*1 int8)
Y = Columns 1 through 9
49 52 55 52 51 52 46 55 50
Columns 10 through 18
54 56 54 44 32 51 44 32 32
Columns 19 through 27
32 48 46 48 48 48 44 32 32
Columns 28 through 36
48 46 48 55 56 44 32 49 48
Columns 37 through 45
46 52 51 52 44 32 53 44 32
Columns 46 through 54
32 55 51 46 57 51 56 44 32
Columns 55 through 63
54 55 46 53 54 50 44 45 56
Columns 64 through 68
52 46 56 49 50
The real data looks like this
X = 147434.72686, 3, 0.000, 0.078, 10.434, 5, 73.938, 67.562,-84.812
It is a CSV array. I want to convert this into a double array, So that I can access each of the values in X as a decimal number.
edit: I'm sorry if the question wasn't clear. I'm getting IMU data from my phone on to matlab, the UDP packets which are actually like X is sent as Y. So inorder to do my computation I need to convert this back to floating point values.(ie change Y to X)
  5 件のコメント
HJ Jay
HJ Jay 2014 年 8 月 3 日
Please check the edited question. I hope it clears things.
Image Analyst
Image Analyst 2014 年 8 月 3 日
Oh, I see now. You're getting x as an ascii string. So the values of Y are the ASCII values of each character of the X.

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

採用された回答

Image Analyst
Image Analyst 2014 年 8 月 3 日
編集済み: Image Analyst 2014 年 8 月 3 日
Y =[49 52 55 52 51 52 46 55 50,...
54 56 54 44 32 51 44 32 32,...
32 48 46 48 48 48 44 32 32,...
48 46 48 55 56 44 32 49 48,...
46 52 51 52 44 32 53 44 32,...
32 55 51 46 57 51 56 44 32,...
54 55 46 53 54 50 44 45 56,...
52 46 56 49 50];
Y(Y==44) = ' ' % Make separator be a space.
x = cell2mat(textscan(char(Y),'%f'))
  1 件のコメント
HJ Jay
HJ Jay 2014 年 8 月 3 日
Thanks a lot, Image analyst.

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

その他の回答 (1 件)

dpb
dpb 2014 年 8 月 3 日
>> v=str2num(char(cell2mat(Y)))
v =
1.0e+05 *
1.4743 0.0000 0
>> v(2)
ans =
3
>>
But, why don't you read the csv file as numeric to begin with????
  1 件のコメント
HJ Jay
HJ Jay 2014 年 8 月 3 日
編集済み: HJ Jay 2014 年 8 月 3 日
Sorry, but I'm afraid it's not working. I've edited the question to get rid of some ambiguity.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by