How to index in for loop
14 次查看(过去 30 天)
显示 更早的评论
I have a an array
a=[4 9 7]
A Matrix
b= [5 7;4 2];
I want to have
c1=4*b c2=9*b; c3=7*b
. I want to use c1,c2"c3' later as d1=r-c1*x; d2=r-c2*x; Where r=[4;9]; x=[3 5]
采纳的回答
David Hill
2021-4-2
编辑:David Hill
2021-4-2
for k=1:length(a)
c(:,:,k)=a(k)*b;%index instead of having different variables
d(:,:,k)=r-c(:,:,k)*x;
end
更多回答(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!