필터 지우기
필터 지우기

Extract from a matrix pairs of consecutive values

조회 수: 1 (최근 30일)
Álvaro Herrador Fernández
Álvaro Herrador Fernández 2022년 11월 24일
편집: Florian Rössing 2022년 11월 24일
Throughout the following code i can represent random numbers. The problem is that i must be able now, not to plot the array and all the values, rather than that, plot with the scatter functin the pairs of consecutive values, but i dont know how to extract all the pairs. Here is the code i have:
clc;
clear all;
a= 37;
b= 1;
m=64;
f= @(x) mod((a*x)+b, m);
x(1)=1;
for i=1:200
x(i+1)= f(x(i));
end
d=0;
for i=1:200
if x(i+1)==x(1)
d=i;
break;
end
end
d
  댓글 수: 1
Florian Rössing
Florian Rössing 2022년 11월 24일
Like you want to plot [x(i),x(i+1)] for all i, or just for odd/even i?

댓글을 달려면 로그인하십시오.

답변 (1개)

Florian Rössing
Florian Rössing 2022년 11월 24일
편집: Florian Rössing 2022년 11월 24일
I would suggest
clc;
clear all;
a= 37;
b= 1;
m=64;
f= @(x) mod((a*x)+b, m);
x(1)=1;
for i=1:200
x(i+1)= f(x(i));
end
d=0;
for i=1:200
if x(i+1)==x(1)
d=i;
break;
end
end
% if you need the odd vs even
x_odd = x(1:2:end);
x_even = x(2:2:end);
%% if x is of odd length, there are more odd indexed numbers, we need to get rid of one.
if mod(length(x),2)~=0
x_odd=x_odd(1:end-1);
end
scatter(x_odd,x_even);
%if you want all x(i)
scatter(x(1:end-1),x(2:end)) % maybe needs some tweaking when the length of x cant be nicely split

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by