Saving For Loop Values Into a Matrix
1 回表示 (過去 30 日間)
古いコメントを表示
for i = 0:0.1:1
for j = 0:0.1:1
if (i^2 + j^2) <= 1
u = (sqrt(i^2 + j^2))^3;
else (i^2 + j^2) > 0
u = 3*sqrt(i^2 + j^2 - 1)+1;
end
end
end
I am looking to store these u values in a matrix u, because I want to plot the surface of u. I am having a hard time storing these values in a matrix. Thanks in advance. I only want to look at u values from 0-1 also if that helps at all.
0 件のコメント
採用された回答
Image Analyst
2021 年 10 月 24 日
Try this:
alli = 0:0.1:1
allj = 0:0.1:1
for k1 = 1 : length(alli)
i = alli(k1);
for k2 = 1 : length(allj)
j = allj(k2);
if (i^2 + j^2) <= 1
u(k1, k2) = (sqrt(i^2 + j^2))^3;
elseif (i^2 + j^2) > 0
u(k1, k2) = 3*sqrt(i^2 + j^2 - 1)+1;
end
end
end
surf(u);
colorbar
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!