how to get no of samples?

4 ビュー (過去 30 日間)
prabhu singh
prabhu singh 2023 年 1 月 19 日
編集済み: VBBV 2023 年 1 月 20 日
a=1:10;
no_samples=(10-1)/(10-1) %have to get 10 samples
no_samples = 1
g=1:no_samples:10;
length(g)
ans = 10
b=9.45:10.55;
no_samples2=(10.55-9.45)/(300-1)%havr to get 300 saamples
no_samples2 = 0.0037
n=9.45:0.0037:10.55;
length(n)
ans = 298
y m getting only 298 samples but i should get 300 samples
i have to get step size value between 9.45 to 10.55 data if i am taking 300 samples

回答 (2 件)

Les Beckham
Les Beckham 2023 年 1 月 19 日
If you want a specific number of samples between two endpoints, use linspace instead of the colon operator:
n = linspace(9.45, 10.55, 300);
length(n)
ans = 300

VBBV
VBBV 2023 年 1 月 19 日
編集済み: VBBV 2023 年 1 月 19 日
format long % this will explain why there are 298 samples
a=1:10;
no_samples=(10-1)/(10-1) %have to get 10 samples
g=1:no_samples:10;
length(g)
b=9.45:10.55;
no_samples2=(10.55-9.45)/(300-1)%havr to get 300 saamples
n=9.45:0.0037:10.55 % there is no 9.45 and 10.55
length(n)
In the first case it was integers , but in the 2nd case, you specified float point decimal, which tells matlab to use preciion arithmetic instead of exact value. Above output shows, even though you used 300, there is no value called 9.45 and 10.55. When you divide it by (300-1), they are 299,
Considering the value of 9.4499999 in place of 9.45, the last value ends less than 10.55 i,e. 10.5489000 and So matlab stops the increment because adding the step size would cross the max value.. Hence the resulting number of samples are 299-1 = 298. hope this clears your doubt
  1 件のコメント
VBBV
VBBV 2023 年 1 月 20 日
編集済み: VBBV 2023 年 1 月 20 日
The -1 seems to do the trick thing when finding the number of samples

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

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by