There is a loop for working with a vector, can it be made to work with a matrix?
z=zeros(100,900); %
x=z(:,1);
y=x;
j=1;
i=1;
u=1;
c=rand(1,900);
for i=1:100
j=j+1;
x(j)=x(i)+0.4*cos(20)/0.226*pi+c(1);
% in the c(1) loop this is because the loop is for the first column,
% in the matrix loop it should be c(num)
u=u+1
y(u)=y(i)+0.64*sin(78)/x(i)*pi+c(1);
end
I will be glad to any advice

댓글 수: 4

Arif Hoq
Arif Hoq 2022년 2월 22일
편집: Arif Hoq 2022년 2월 22일
what is value of "a" ? if i choose the variable "a" as a random number, then
a=randi(10,1,100);
z=zeros(100,900); %
x=z(:,1);
y=x;
j=1;
i=1;
u=1;
c=rand(1,900);
for i=1:100
j=j+1;
x(j)=x(i)+0.4*cos(20)/0.226*pi+c(1);
% in the c(1) loop this is because the loop is for the first column,
% in the matrix loop it should be c(num)
u=u+1;
y(u)=y(i)+0.64*sin(78)/a(i)*pi+c(1);
end
Lev Mihailov
Lev Mihailov 2022년 2월 22일
the value of "a" is the value of "x", in future versions of the code, the variable "a" had to be abandoned
Dyuman Joshi
Dyuman Joshi 2022년 2월 22일
Which variable(s) is/are supposed to be a matrix?
KSSV
KSSV 2022년 2월 22일
It looks like you need not to use a loop here....tell us your problem, you can vectorize the code striaght away.

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

 채택된 답변

DGM
DGM 2022년 2월 22일
편집: DGM 2022년 2월 22일

0 개 추천

You mean like this?
c = rand(1,900);
x = zeros(100,900);
y = x;
for k = 1:99
x(k+1,:) = x(k,:) + 0.4*cos(20)/0.226*pi + c;
y(k+1,:) = y(k,:) + 0.64*sin(78)./x(k,:)*pi + c;
end
... but I should ask how you say it's working when it's clearly dividing by zero and creating an entire array of Infs

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2022년 2월 22일

편집:

DGM
2022년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by