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

采纳的回答

KSSV
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 个)

类别

Help CenterFile Exchange 中查找有关 Instrument Control Toolbox Supported Hardware 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by