How to call two sets of arrays in a nested loop?

3 次查看(过去 30 天)
Hello Experts,
I have taken two sets of arrays. First one is 'alpha', which consists of 251 elements, the second one is 't', which consists of 721 data points.
For each alpha, I need to evaluate 'M', and thereby, (M*cos(t), M*sin(t)), which describes a 2 dimensional family of curves.
I need to create a dataset for 'M' considering each value of 'alpha' varying the values of 't' from 0 to 2*pi, and constructed the code expecting a matrix of [251*721] order. But the code returns only one value for M. There is no error message. Please help with your enlightened view.
Hirak
a=45;
x1=1:.02:6;
alpha=x1.^4;
t = 0:(pi/360):2*pi;
array=zeros(251,721);
for k1=1:.02:6
for k2=0:(pi/360):2*pi
M=a.*sqrt(cos(2.*k2)+sqrt(k1+(sin(2*k2).^2)));
x = M.*cos(k2);
y = M.*sin(k2);
end
end

采纳的回答

VBBV
VBBV 2021-4-14
%if true
a=45;
x1=1:.02:6;
alpha=x1.^4;
t = 0:(pi/360):2*pi;
%rray=zeros(251,721);
p = 0:(pi/360):2*pi;
K = 1:0.02:6;
for k1= 1:length(K)
for k2=1:length(p)
M(k1,k2) =a*sqrt(cos(2*p(k2))+sqrt(K(k1)+(sin(2*p(k2).^2)));
x(k2) = M(k1,k2)*cos(p(k2));
y(k2) = M(k1,k2)*sin(p(k2));
end
end
Try this
  1 个评论
Hirak
Hirak 2021-4-14
编辑:Hirak 2021-4-14
Tried the code, but it appears k1 and k2 is not changing for x and y. I have just chnged it to
x(k1,k2) = M(k1,k2).*cos(p(k2));
y(k1,k2) = M(k1,k2).*sin(p(k2));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by