ある行の任意値の数を数えるコードを作りたい
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
翔 池田
am 21 Apr. 2021
Beantwortet: Hernia Baby
am 21 Apr. 2021
ある行の任意の値の数を求めるコードをfor文なしで作成したいのですがどういうアルゴリズムにすればよいか悩んでいます.
例えば,
A=[1,1,2,3;1,1,1,2];
A行列に対して,1行目は’1’が2個,2行目は'1'が3個なので
ans=[2;3]というように出したいです.
お手数ですが,ご教授いただきたいです.
0 Kommentare
Akzeptierte Antwort
Hernia Baby
am 21 Apr. 2021
logical値にしてそれをカウントすれば可能です
A=[1,1,2,3;1,1,1,2];
sum(A==1,2)
ans =
2
3
-------------------------
sum(X,dir)はdirの番号でどの方向に合計値をとるか決めます
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Particle & Nuclear Physics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!