How to generate chaotic index between 1 and 256 by hybrid sin-cos map?
1 次查看(过去 30 天)
显示 更早的评论
lease fix my error....
I have this problem in mode function :"Error using mod
Arguments must be real.
Pos=mod(xx,size);"
I need " Pos " to be value from 1 to 256 ( integer value , I need use it as index in confusion phase)
%-------------------------code---------------------------
clc;
clear all;
size=256;
x=nan(1,size+1); %<------------PREALLOCATE!!!
y=nan(1,size+1); %<------------PREALLOCATE!!!
Z=0.78;% initial value of control parameter Z for cofusion
E=0.95;% initial value of control parameter E for cofusion
x(1)=0.75;% initial value
y(1)=0.2963 ; % initial value
for j=1:size
r=(Z/y(j))^(3/2);
x(j+1)=sin(r);
w=E*acos(x(j));
y(j+1)=cos(w);
end
xx=round(x(2:size+1)*10^14);
Pos=mod(xx,size);
0 个评论
回答(1 个)
Voss
2021-12-28
The answer is the same as the answer to a previous question: https://www.mathworks.com/matlabcentral/answers/1608410-how-to-confusion-image-by-sin-cos-map#answer_852520
To wit: At some point in your for j=1:size loop, y(j+1) becomes negative, so in the next iteration r is complex. This is the source of the "Arguments must be real" error. I don't know how you might fix it.
(BTW, if you make a variable called size, then you won't be able to use the size() function while that variable is defined. Use siz or something else that's not the name of a function.)
2 个评论
Voss
2021-12-28
It's just math, so you'll have to decide what you really want the program to do. That is, how to handle the case when cos(w) goes negative. I don't know what this program is for or where the equations come from or what assumptions are made (assumptions which the program may be violating), but the error with mod is only a symptom.
另请参阅
类别
在 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!