How to create dynamic array with flexible index?

조회 수: 4 (최근 30일)
Ad
Ad 2017년 5월 5일
댓글: Walter Roberson 2017년 5월 7일
I am working with an RGB image and I am new to matlab.I have generated a probability matrix 1*40. Now I want to create a dynamic array with flexible index because I don't know how many values will satisfy the condition(I want to change 'P' to 1*80). for example P={0.4,0.5,0.7,0.2,0.1,0.9,0.5,0.4..........(40 values)}.If value ==0.5 I want to store the index value in an array. A(1)={2},A(2)={7}.....
Thanks in advance.

채택된 답변

KSSV
KSSV 2017년 5월 5일
A = rand(1,40) ;
%%values of A less then 0.5
P = A(A<0.5) ;
%%indices of A less then 0.5
idx = find(A<0.5) ;
You need not to worry about the dimension of array which you want obeying certain condition.
  댓글 수: 6
Ad
Ad 2017년 5월 5일
편집: Ad 2017년 5월 5일
@KSSV,STEPHEN COBELDICK and ADAM.
Thank you so much guys for your kind support.
Walter Roberson
Walter Roberson 2017년 5월 7일
Out of all of those values, 0.5 is the only one that you can hope to be able to find by using equality testing.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by