matrix 0f {0,1}

2 次查看(过去 30 天)
Sara
Sara 2022-12-11
评论: Sara 2022-12-11
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 个评论
Jan
Jan 2022-12-11
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 2022-12-11
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

请先登录,再进行评论。

回答(1 个)

John D'Errico
John D'Errico 2022-12-11
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 个评论
Sara
Sara 2022-12-11
Thanks for your effort i will try this

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by