Duplicate the value of a cell for other cells in a matrix

Hello everyone,
I have a large-size matrix A with 100 rows and 1000 columns. I was wondering how I can duplicate the value of a single cell to some other cells. For example, lets assume A(2,5)=4. Then, how can I have the same value for other 1000 cells of matrix A? These 1000 cells can be of any row and column.
For this sake, my main concern is to speed up the run and avoid as loops as possible.
Any help or remark is highly appreciated! Thank you!

3 commentaires

Matt Fig
Matt Fig le 6 Sep 2012
Modifié(e) : Matt Fig le 6 Sep 2012
By the way, in MATLAB a cell array is a specific thing. If you are talking about a numerical array (a matrix for example), then they are elements, not cells.

Connectez-vous pour commenter.

 Réponse acceptée

Matt Fig
Matt Fig le 6 Sep 2012
Modifié(e) : Matt Fig le 6 Sep 2012
Here is an example; adapt it as needed.
A = magic(10); % The array.
N = randperm(numel(A)); % Random linear indices.
A(N(1:20)) = A(1,1); % Set 20 random elements of A to equal A(1,1).

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by