How to check the number of ones from certain row to the 1st row?

조회 수: 1 (최근 30일)
fyza affandi
fyza affandi 2018년 11월 27일
답변: Bruno Luong 2018년 11월 27일
t(:,:,1) =
1 10 19 28 37 46 55 64 73 82
2 11 20 29 38 47 56 65 74 83
3 12 21 30 39 48 57 66 75 84
4 13 22 31 40 49 58 67 76 85
5 14 23 32 41 50 59 68 77 86
6 15 24 33 42 51 60 69 78 87
7 16 25 34 43 1 61 70 79 88
8 17 26 35 44 53 1 1 80 89
9 18 27 36 45 54 63 72 1 1
t(:,:,2) =
91 100 109 118 127 136 145 154 163 172
92 101 110 119 128 137 146 155 164 173
93 102 111 120 129 138 147 156 165 174
94 103 112 121 130 139 148 157 166 175
95 104 113 122 131 140 149 158 167 176
96 105 114 123 132 141 150 159 168 177
1 106 115 124 133 142 151 160 169 178
98 107 116 125 134 143 152 161 170 179
99 108 117 126 135 144 153 162 171 180
I want to get the ones by row. Using above code, I get the number of ones by column.
squeeze( sum( t(1:7, :, :) == 1, 1 ) )
ans
1 1
0 0
0 0
0 0
0 0
1 0
0 0
0 0
0 0
0 0
I want to get the result as below:- (but I cant get it)
ans
1 0
0 0
0 0
0 0
0 0
0 0
1 1
0 0
0 0
  댓글 수: 2
madhan ravi
madhan ravi 2018년 11월 27일
편집: madhan ravi 2018년 11월 27일
the pattern is not discernible , need more explanation
fyza affandi
fyza affandi 2018년 11월 27일
편집: fyza affandi 2018년 11월 27일
For each row, I want to get the number of ones. In t(:,:,1) , there is ones in row 1 and row 7
.In t(:,:,2) , there is ones in row 7.
The number of ones to becounted is starting from row 7 untill the 1st row for both matrices.
1 0
0 0
0 0
0 0
0 0
0 0
1 1
0 0
0 0

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2018년 11월 27일
>> squeeze(sum(t(1:7,:,:)==1,2))
ans =
1 0
0 0
0 0
0 0
0 0
0 0
1 1

추가 답변 (1개)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy 2018년 11월 27일
MathWorks Please use this

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by