How to call two sets of arrays in a nested loop?
1 回表示 (過去 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
0 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!