constructing matrix with loop
显示 更早的评论
I have 3 matrix consist of numeric values as follows;
XY_j=[Xj_ref, Yj_ref]; %consists of 2 column and 40 rows (40x2)
XY_orj=[x_orj, y_orj]; %consists of 2 column and 205 rows (205x2)
C; %consists of one column and 40 rows (40x1)
I need to form below calculation with loop;
for i=1:40
Ne_sum_1(i)=C_matrix(i)*(sqrt((x_orj(1)-Xj_ref(i))^2+(y_orj(1)-Yj_ref(i))^2));
Ne_sum_2(i)=C_matrix(i)*(sqrt((x_orj(2)-Xj_ref(i))^2+(y_orj(2)-Yj_ref(i))^2));
Ne_sum_3(i)=C_matrix(i)*(sqrt((x_orj(3)-Xj_ref(i))^2+(y_orj(3)-Yj_ref(i))^2));
.
.
.
Ne_sum_205(i)=C_matrix(i)*(sqrt((x_orj(205)-Xj_ref(i))^2+(y_orj(205)-Yj_ref(i))^2));
end
sum_1=(sum(Ne_sum_1));
sum_2=(sum(Ne_sum_2));
sum_3=(sum(Ne_sum_3));
.
.
.
sum_205=(sum(Ne_sum_205));
After the above calculation 205 Ne_sum are created. How can I modify above computation with loop?
2 个评论
The most important step is to realize that creating lots of separate variables is a really bad way to program. You should never create (or access) numbered variables like that, this is very slow and buggy. Here is why:
sermet
2016-3-20
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 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!