フィルターのクリア

Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
shahin hashemi
shahin hashemi 2019 年 1 月 14 日
コメント済み: shahin hashemi 2019 年 1 月 14 日
dear all
i have code like below
clc
clear all
for b=1:0.1:20
M((b*10)-9,:)=[1 1 1 ]
end
but at b=2.4 i got this error :
M =
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
Subscript indices must either be real positive integers
or logicals.
Error in Untitled2 (line 4)
M((b*10)-9,:)=[1 1 1 ]
i really appreciated if some can help me y i get this error and what the solotions ?
  3 件のコメント
Stephen23
Stephen23 2019 年 1 月 14 日
"i really appreciated if some can help me y i get this error..."
"...and what the solotions ?"
Do not do calculations on floating point numbers and expect to get exact integer outputs. Write your code knowing that calculations on floating point numbers accumulate floating point error.
shahin hashemi
shahin hashemi 2019 年 1 月 14 日
thank you very much
i use round and got answer
u cooment so i cant accept your answer

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

採用された回答

Stephen23
Stephen23 2019 年 1 月 14 日
編集済み: Stephen23 2019 年 1 月 14 日
Better to iterate over integer indices rather than fractional values:
V = 1:0.1:20;
N = numel(V);
M = nan(N,3);
for k = 1:N
M(k,:) = [1,1,1];
end
Even better:
M = repmat([1,1,1],N,1)
Best:
M = ones(N,3)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by