フィルターのクリア

how to delete decimal places

1 回表示 (過去 30 日間)
Offroad Jeep
Offroad Jeep 2022 年 10 月 22 日
コメント済み: Offroad Jeep 2022 年 10 月 22 日
clc
clear all
format long
a = 1
b = 90
r = a + (b-a)*rand()
N=3
r = a + (b-a)*rand(N,N)
Question 1. how to ignore the decimal part... i mean if matrix element is 12.23626563 i only want 12
regards....

採用された回答

dpb
dpb 2022 年 10 月 22 日
'Pends.
You mean just at the display or in the actual data?
If it's for the display, there isn't an "integer" format option; 'short' or maybe 'bank' (2 decimals F format) is about as fine as it gets unless you write the output with formatted io like
num2str(x,0)
If you mean you want integral valued values for the variable r itself, then
r=round(a + (b-a)*rand(N));
does the trick.
Although can save a step by using randi instead
r=randi([a,b],N);
  1 件のコメント
Offroad Jeep
Offroad Jeep 2022 年 10 月 22 日
Thanks.... great......

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by