필터 지우기
필터 지우기

need function to compute iterations of element in matrix

조회 수: 1 (최근 30일)
Abdulkareem
Abdulkareem 2014년 1월 28일
댓글: Abdulkareem 2014년 1월 28일
hi every body i need matlab function to compute the number of iterations of one elements in matrix just like in excel when u want to compute for example how much the No. 3 occur in some column = counif(a1:a10;"=3") { in excel } is there a function in matlab can do the same thinks
tanks in advance

채택된 답변

AJ von Alt
AJ von Alt 2014년 1월 28일
One approach is to create a logical matrix for the input by comparing it to the target value. You can then sum a row, column, or the whole matrix to get the number of instances, since each instance is indicated by a 1.
% create a 50 x 50 matrix taking integers between 1 and 10
M = randi( 10 , 50 , 50 );
% the value you wish to count instances of
targetVal = 3;
% create logical matrix indicating presence of targetVal at location
isTarget = (M == targetVal);
% Find the number of instances in the matrix
nVals = sum( isTarget(:) );
% Find the number of instances in row 3
nvalsR3 = sum( isTarget(3,:) );
% Find the number of instances in column 12
nvalsC12 = sum( isTarget(:,12) );
  댓글 수: 1
Abdulkareem
Abdulkareem 2014년 1월 28일
thank u very much mr. AJ von Alt u answer solve the problem

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 28일
편집: Azzi Abdelmalek 2014년 1월 28일
A=[1 2 3;3 0 1;4 5 6;3 1 5]
n1=sum(A(:,1)==3) % number of 3 in the first column
n2=sum(A(:,3)==3) % number of 3 in the third column

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by