Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with vectors in MATLAB

Status
Not open for further replies.

john2009

Bioengineer
Apr 21, 2010
1
Hi,

I need some help with vectors in Matlab.

I have a vector A with 100 elements. From previous calculations, 80 of the elements are 1 and the rest are zero.
But I need to make the vector with half of its element "zero" and the remaining half "one" by randomly turning some of the one's to zero.

So I need to turn 30 (out of 80 currently in the vector) 1's into zero and I have to do it randomly. Can anyone help me with this problem?

Thanks,
John.
 
Replies continue below

Recommended for you

homework?

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Code:
N_init = 80;
N_reqd = 50;
idxrand = randperm(N_init);
idx1 = find(A);
A(idx1(idxrand(1:N_init-N_reqd))) = zeros(1,N_init-N_reqd);

M

--
Dr Michael F Platten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor