Clear Filters
Clear Filters

matrix 0f {0,1}

2 views (last 30 days)
Sara
Sara on 11 Dec 2022
Commented: Sara on 11 Dec 2022
i have a matrix B=M*K /M=36 ,K=10 i will sort this matrix in descending -[x , I] = sort (B , 'descend') and i want to take the elements (1:4) for vector M and check for element by element for vector K -for i = 1:K -u=X(1:4,i) and i have constraint for i -if i satisfy constraint then i have to put ones for these (1:4) M elements and give a zero to the other elements of M how can i do this ? how can i give ones to (1:4) elements and zeros to the rest of the elements of this vector M
  2 Comments
Jan
Jan on 11 Dec 2022
The question is not clear. Is "b" the same as "B"? If M and K are vectors, which dimensions do they have to let B be a matrix? If K is a vector, what does "for i=1:K" mean? What is X?
Sara
Sara on 11 Dec 2022
I edit the question and put the values of M and K / and i is one of the elements of K vector The loop i= 1:K means that i want to check for all K elements vector/ and X is the sorted of B

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 11 Dec 2022
About as confusing a question as I could imagine, but after reading it several times, I will make a guess.
I think in the end, you just need to learn how to set a column of a matrix where the first 4 elements are 1, and the remainder of the elements are 0. I think that is all you are asking. Somehow, I doubt I am right. But that is my conjecture. Anyway, do this:
x(:,i) = [ones(4,1),zeros(M-4,1)];
  1 Comment
Sara
Sara on 11 Dec 2022
Thanks for your effort i will try this

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!