Hello all,
Ive a simple problem that probably has a simple solution that I cant quite grasp as I am a bit of a novice.
I have an array of size 103x15, through which I have some negative values. I want to extract the position of these values into another array so that I can highlight and then total them up and find the percentage of negative values as a proportion of all the data.
Thank you!
for n=1:length(X)
neg=find(X(n,1:15)<0)
end

 채택된 답변

Star Strider
Star Strider 2020년 12월 4일

1 개 추천

I’m not certain what you want to do.
See if this works in your application:
X = randn(103, 15); % Normally-Distributed Random Numbers
neg = X < 0; % Logical Array Of Positions Of Negative Values
nr_neg = sum(neg,'all'); % Can Alse Use ‘nnz’ Instead Of Sum
sum_neg = sum(X(neg),'all'); % Sum Of All Negative Elements
prop_neg = nr_neg / numel(X); % Proportion Of Elements That Are Negative
prop_neg_vals = sum_neg / sum(X,'all'); % Sum Of Negative Values As Proportion Of All Values
.

댓글 수: 2

Magnus Bichan
Magnus Bichan 2020년 12월 6일
Worked a charm, thank you! My tired mind making it more complicated than it had to be. Much appreciated!
Star Strider
Star Strider 2020년 12월 6일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 12월 4일

댓글:

2020년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by