Suppose x = rand(1e5,1e5);
I want to find the lowest number in each column of x without using for loop.
Is it possible?

 채택된 답변

Stephen23
Stephen23 2020년 4월 10일

1 개 추천

"find the first value in each column which lis ess than 0.25 but greater than 0.2."
>> x = rand(13,7)
x =
0.833676 0.654529 0.869031 0.922756 0.586565 0.278136 0.595271
0.335144 0.936490 0.552751 0.676447 0.924786 0.813253 0.388776
0.171351 0.992074 0.426227 0.814150 0.599205 0.378885 0.470132
0.368957 0.162066 0.044178 0.911514 0.431260 0.111011 0.348894
0.787866 0.150796 0.783209 0.406310 0.116503 0.232302 0.350849
0.676606 0.782741 0.251472 0.223849 0.872576 0.665249 0.287961
0.176415 0.750830 0.958001 0.274026 0.107420 0.716966 0.612980
0.030644 0.103396 0.297286 0.256401 0.902245 0.486087 0.812681
0.563573 0.414845 0.615615 0.335131 0.589437 0.396942 0.780523
0.994748 0.314337 0.721215 0.946815 0.446822 0.252527 0.593235
0.438298 0.516228 0.978322 0.183097 0.011558 0.731435 0.948024
0.496606 0.172242 0.224708 0.339960 0.425773 0.730056 0.809002
0.234744 0.195880 0.086287 0.702632 0.708232 0.489843 0.558111
>> y = x>0.2 & x<0.25;
>> [row,col] = find(y & cumsum(y,1)==1)
row =
13
12
6
5
col =
1
3
4
6

추가 답변 (1개)

David Hill
David Hill 2020년 4월 9일

0 개 추천

min(x);

댓글 수: 3

parham kianian
parham kianian 2020년 4월 9일
편집: parham kianian 2020년 4월 9일
Let me to clarify the question.
Suppose it is aimed to find the first value in each column which lis ess than 0.25 but greater than 0.2.
How can I do that?
x = rand(1e4);
a = x.*(x>.2&x<.25);
b=arrayfun(@(y)a(find(a(:,y),1),y),1:size(a,2));
parham kianian
parham kianian 2020년 4월 10일
Thank you David. It works well. But the method suggested by Stephen is a little easier.

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2020년 4월 9일

댓글:

2020년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by