Set a value of a specific column for each row of a matrix

后端 未结 1 1812
感动是毒
感动是毒 2021-01-25 09:55

I have a matrix A with m rows and I\'d like to set a specific element of each row equal 1. The column index varies from row to row and is specified by

1条回答
  •  不思量自难忘°
    2021-01-25 10:33

    I solved it using the sub2ind function:

    A(sub2ind(size(A), 1:numel(a), a')) = 1
    

    0 讨论(0)
提交回复
热议问题