Returning index values (elements) of a randomly generated matrix (using ceil command) in Matlab

조회 수: 1 (최근 30일)
Hi
I have a matrix/vector that has 100 randomly generated values of 0 or 1 as:
matrix_nodes = ceil( rand(1,number_nodes)*2)-1
Now, from the above matrix/vector, I want two matrices/vectors such that I get all values (elements) which are 1 and 0 from matrix_n respectively:
matrix_ones = find(matrix_nodes==1)
matrix_zeros = find(matrix_nodes==0)
  • But the above code only return the indices of all the ones in matrix_n. *
Can anyone help me how to get values of all the ones from matrix_n in matrix_ones and values of all zeros from matrix_n in matrix_zeros.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 23일
편집: Azzi Abdelmalek 2014년 3월 23일
matrix_ones =matrix_nodes(matrix_nodes==1)
matrix_zeros = matrix_nodes(matrix_nodes==0)
  댓글 수: 2
Syed
Syed 2014년 3월 23일
편집: Syed 2014년 3월 23일
Thanks
Could you also tell me how can I increase the concentration of zeros in the above matrix (matrix_nodes) such that I have more random ones generated than zeros.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 23일
편집: Azzi Abdelmalek 2014년 3월 23일
number_nodes=100
m=0.7
matrix_nodes=rand(1,number_nodes)<m
to get, approximately, the same number put m=0.5; m can vary from 0 to 1

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by