Convert vector loop to matrix loop
Ältere Kommentare anzeigen
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 Kommentare
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
am 22 Feb. 2022
Dyuman Joshi
am 22 Feb. 2022
Which variable(s) is/are supposed to be a matrix?
KSSV
am 22 Feb. 2022
It looks like you need not to use a loop here....tell us your problem, you can vectorize the code striaght away.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!