Two Matrix array elements addition except the very first one

2 ビュー (過去 30 日間)
altaf ahmed
altaf ahmed 2019 年 4 月 28 日
回答済み: Prasanna Venkateshan 2020 年 7 月 7 日
I have a matrix of 10x10000 and want to add previous column with current one excpoet the very first one like below:
First Row contents are suppose: a1 a2 a3 a4 .....
After Addition operation, new matrix result as: a1 a2+a1 a3+a2 a4+a3 .......
So a1 reamins a1. All other subsequent are added to prevoius column values for all rows in a series.
Sample non-working code that I generated is below:
N = 10; % 10 terminals in the TDMA system
TOTAL_SERVED_PACKETS = 100000;
num_arrivals = TOTAL_SERVED_PACKETS/N;
interarrival_time = exprnd(mean_interarrival, N, num_arrivals);
for arrival_loop = 2:num_arrivals %iterate through Interaarival time array for each station
for station_num = 1:N %iterate through the arrays for all stations
offset = 1;
arrival_list = interarrival_time(station_num,arrival_loop-offset)+interarrival_time(station_num,arrival_loop);
offset = offset + 1;
arrival_loop = arrival_loop + 1;
if station_num == N
end
if arrival_loop == num_arrivals
end
end
end
I am getting this error: Index in position 2 exceeds array bounds (must not exceed 10000).

採用された回答

Prasanna Venkateshan
Prasanna Venkateshan 2020 年 7 月 7 日
matrix=[1 2 3 4;5 6 7 8;9 10 11 12];
for i=1:size(matrix,1)
for j=size(matrix,2):-1:2
matrix(i,j)=matrix(i,j)+matrix(i,j-1);
end
end
disp(matrix)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by