Getting the percentage of values greater then 0.3 using linear and subscript indexing.

조회 수: 1 (최근 30일)
Hi all, I'm currently trying to find the percentage of values greater than 0.3 through just linear and subsccript indexing. I'm currently using logic indexing but I'm not sure how to do it without logic indexing. Any help would be very much appreciated. My current code is below.
clearvars
clc
close all
A1 = rand(20,30);
B1 = A1 > .3;
C1 = A1(B1);
D1 = sum(C1,1)./(20.*30).*100;
A2 = rand(50,50);
B2 = A2 > .3;
C2 = A2(B2);
D2 = sum(C2,1)./(50.*50).*100;
A3 = rand(100,100);
B3 = A3 > .3;
C3 = A3(B3);
D3 = sum(C3,1)./(100.*100).*100;
A4 = rand(200,200);
B4 = A4 > .3;
C4 = A4(B4);
D4 = sum(C4,1)./(202.*200).*100;
PRCT03 = [D1 D2 D3 D4];

채택된 답변

Image Analyst
Image Analyst 2022년 10월 14일
% Using logical indexing
A1 = rand(20,30);
pct = 100 * sum(A1 > 0.3, 'all') / numel(A1)
pct = 68.5000
% Using linear indexing
linearIndexes = find(A1 > 0.3)
linearIndexes = 411×1
4 5 6 7 9 10 11 12 13 16
pct = 100 * length(linearIndexes) / numel(A1)
pct = 68.5000

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by