storing floating point values in an array

I want to do a calculation which gives answer in float. then i want to store that answer in an array. when i tried to do so, the array is converting that float value to nearby integer. can anybody tell me how to get out of it.

1 件のコメント

TAB
TAB 2012 年 1 月 30 日
We can not guess what are you doing by just reading the description. Please post your code.

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

 採用された回答

Jan
Jan 2012 年 1 月 30 日

1 投票

If you declare a variable and insert values later, the type of the variable is not changed:
a = zeros(10, 1, 'uint8');
a(1) = pi;
class(a) % >> UINT8 !
disp(a)
% >> 3
Therefore the variable must be either defined explicitely using the wanted class:
a = zeros(10, 1, 'double');
% or simply: a = zeros(10, 1);
Or let Matlab choose the type automatically by omitting the explicite pre-allocation:
a(10) = theFunction();
Now you can start with the last element for an implicite pre-allocation.

1 件のコメント

Rashmi
Rashmi 2012 年 2 月 2 日
Thnx.... it really worked.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2012 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by