Filter löschen
Filter löschen

matrix 0f {0,1}

2 Ansichten (letzte 30 Tage)
Sara
Sara am 11 Dez. 2022
Kommentiert: Sara am 11 Dez. 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 Kommentare
Jan
Jan am 11 Dez. 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 am 11 Dez. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 11 Dez. 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 Kommentar
Sara
Sara am 11 Dez. 2022
Thanks for your effort i will try this

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by