Get a new matrix from another matrix through loop
1 次查看(过去 30 天)
显示 更早的评论
Dear all,
I want to obtain matrix D_GW from D_AQ where:
D_GW = [a b c; d e f];
D_AQ = [(b-a) (c-b); (e-d) (f-e)];
To do this, I have set the initial column of D_GW as 0 and simply add D_AQ but I keep getting the error "Index in position 1 exceeds array bounds (must not exceed 1)". Any help is greatly appreciated. Thank you.
D_GW = [];
D_GW(:,1) = 0;
D_AQ = [2 3; 5 6]; % D_GW = [0 2 5; 0 5 11]
for row = 1:size(D_AQ,1)
for col = 1:size(D_AQ,2)
D_GW(row,col+1) = D_GW(row,col) + D_AQ(row,col);
end
end
0 个评论
采纳的回答
KSSV
2021-1-6
D_GW = zeros(2,3);
D_GW(:,1) = 0;
D_AQ = [2 3; 5 6]; % D_GW = [0 2 5; 0 5 11]
for row = 1:size(D_AQ,1)
for col = 1:size(D_AQ,2)
D_GW(row,col+1) = D_GW(row,col) + D_AQ(row,col);
end
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Instrument Control Toolbox Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!