see, i have this error in my code saying: ??? Attempted to access x(0); index must be a positive integer or logical. Error in ==> abc at 14 x(i)=mod(g^x(i-1), p); how could index 0 not be a posiitive integer? :
1 回表示 (過去 30 日間)
古いコメントを表示
% Implementarea algoritmului Blum Micali
% pentru PRNG in Matlab
clear all; close all; clc;
p = input('Introduceti numarul prim p= ');
g = input('Introduceti numarul prim g= ');
Nr=p-1;
x=zeros(1, Nr);
for i=1:Nr
x(i)=mod(g^x(i-1), p);
end;
disp('Rezultatul este: ');
disp(x);
2 件のコメント
Steven Lord
2015 年 7 月 16 日
By the usual definition of "positive" as it relates to numbers, 0 is not positive since 0 > 0 returns false.
Numeric data used as indices in MATLAB must contain only real positive finite integer values. There is no such thing as x(0) [no zeroth element] when x is a numeric variable. [I'm ignoring logical indexing for purposes of this comment; that's different.]
Walter Roberson
2015 年 7 月 16 日
Duplicated by http://uk.mathworks.com/matlabcentral/answers/230110-see-i-have-this-error-in-my-code-saying-attempted-to-access-x-0-index-must-be-a-positive-int which also has answers
回答 (1 件)
Azzi Abdelmalek
2015 年 7 月 16 日
編集済み: Azzi Abdelmalek
2015 年 7 月 16 日
When i=1, you can't write x(i-1), because i-1=0. Matlab does not accept an index equal to 0
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!