change the number of digits after decimal point

Hi everybody
how can I change the number of digits after decimal point? I have a matrix of float numbers i want to transform each number in this matrix from this form x.xxxxxxxxxxxxxxx to this form x.xxxx
thanks

 採用された回答

Mahdi
Mahdi 2014 年 5 月 30 日
編集済み: Mahdi 2014 年 5 月 30 日

1 投票

You can use the sprintf or the format option. In your case, you can just type:
format short
into the command window.

3 件のコメント

jan
jan 2014 年 5 月 30 日
編集済み: jan 2014 年 5 月 30 日
Hi Mahdi and thanks for your answer, sprintf is to transform the data to string which isn't my interest fprintf for displaying and i used format short in the command window but nothing is changed. I need to transform all the values in the matrix with only 4 digits numbers and not 15 because i will do a treatement on it so it isn't a problem of displaying
Mahdi
Mahdi 2014 年 5 月 30 日
編集済み: Mahdi 2014 年 5 月 30 日
Try putting format short into your script? Do you mind attaching your code? It should work for your purposes.
I strongly do not recommend doing it this way, but as a last resort, you can change your string to a number using str2num.
jan
jan 2014 年 5 月 30 日
Thanks mehdi even it isn't a direct way but it gives what i need thanks a lot

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

その他の回答 (2 件)

Image Analyst
Image Analyst 2014 年 5 月 30 日

0 投票

(I should add this to the FAQ.)

4 件のコメント

jan
jan 2014 年 5 月 30 日
編集済み: jan 2014 年 5 月 30 日
thanks Image Analyst for response but it isn't really what i'm looking for
Image Analyst
Image Analyst 2014 年 5 月 30 日
編集済み: Image Analyst 2014 年 11 月 29 日
Then why don't you describe exactly what you're looking for? I see two possibilities: Do you want to (a) change each number by truncating digits after a certain number of decimal places, or (b) leave each number alone but just change how many digits are displayed when you display it in the command window or a static text label in a GUI?
I told you how to do (a). To do (b) you can use sprintf(), fprintf(), or format(). Which way, a or b, do you want to do?
jan
jan 2014 年 5 月 30 日
編集済み: jan 2014 年 5 月 30 日
Hi I'm looking for b but sprintf is to transform the data to string which isn't my interest fprintf for displaying and i used format short in the command window but nothing is change. I need to transform all the values in the matrix with only 4 digits numbers and not 15 because i will do a treatement on it so it isn't a problem of displaying
Image Analyst
Image Analyst 2014 年 5 月 30 日
編集済み: Image Analyst 2014 年 11 月 29 日
You said you want (b) but then you say that you don't want to use sprintf() or format() or to use a string at all. Your last sentence indicates that you want it to stay a number not a string but that is option (a) and is the answer I gave you at the very start. Sorry but I still am not sure what you want. You're either changing the number (by chopping off digits) or you're not, which is it?

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

rahul bathini
rahul bathini 2015 年 6 月 26 日

0 投票

I've made a simulation on BPSK modulation and semilogy plotted the SNR vs. BER. The plot is geometrically the same to the actual plot but deviates from BER = 0.00001.I think this is because matlab doesn't consider values below 4 decimal place while plotting , to what extent could this be the reason if not what could the reason be.plz someone help me

カテゴリ

質問済み:

jan
2014 年 5 月 30 日

回答済み:

2015 年 6 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by