Adding Column values of a matrix
이전 댓글 표시
Hi, I have a matrix like below.
all_one_matrix(:,:,1)
ans =
Columns 1 through 8
0.1979 0.1979 0.1354 0.0729 0.3542 0.3021 0.1771 0.0729
0.4167 0.0938 0.2708 0.3958 0.0417 0.1042 0.3438 0.4583
0.1250 0.1771 0.1354 0.1146 0.0938 0.1771 0.1771 0.1042
0.1563 0.1146 0.1563 0.1667 0.1458 0.0833 0.1354 0.1146
0.0417 0.0521 0.0521 0.0729 0 0.0625 0.1250 0.1250
Columns 9 through 16
0.1458 0.2813 0.1458 0.3125 0.1771 0.1875 0.0938 0.1875
0.1875 0.1146 0.2292 0.1354 0.0625 0.2708 0.2396 0.0729
0.0625 0.0521 0.1563 0.0417 0.0938 0.1042 0.2604 0.1042
0.2083 0.2500 0.1042 0.0729 0.2813 0.1042 0.1042 0.0833
0.0625 0.1354 0.1875 0.0938 0.1458 0.2292 0.1979 0.1771
i want to add the values of column row wise. i.e i have 16 column in row first, i need the sum of all 16 column of first row, row 2, row 3, row 4 and row 5.
how can i do it ? thanks in advance
댓글 수: 1
Azzi Abdelmalek
2013년 2월 6일
Give a small example that correspond to your problem
답변 (1개)
Walter Roberson
2013년 2월 6일
sum(all_one_matrix(:,:,1), 2)
댓글 수: 9
M@lik Ali
2013년 2월 6일
Walter Roberson
2013년 2월 6일
You said "Like in above case fset(:,:,3) will be fset(:,:,1) but actually it was 3" but you are referring to the same array in both cases. Perhaps you meant to refer to iundex or sorted_fset in one of those two variables?
The first output index would be 3 because you set plane 3 to all zeros and rand() is always greater than 0 so plane 3 is going to sort earlier than plane 1 or 2. The 3 in the first position indicates that the 3rd entity was what sorted first.
M@lik Ali
2013년 2월 6일
Walter Roberson
2013년 2월 6일
Look at iundex(:,:,1)
M@lik Ali
2013년 2월 6일
Walter Roberson
2013년 2월 6일
[B,IX] = sort(A,...) [...]
If A has repeated elements of equal value, the returned indices preserve the original ordering.
M@lik Ali
2013년 2월 6일
Walter Roberson
2013년 2월 6일
Please give a specific example of data and the command you use, and show the particular output value we should look at and the result you expect and the result you currently get.
M@lik Ali
2013년 2월 6일
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!