# How to make specific elements of a cell equal to zero?

11 visualizzazioni (ultimi 30 giorni)
Haitham AL Satai il 15 Set 2022
Risposto: Walter Roberson il 15 Set 2022
I have a cell 41 * 41 dimension and I would like to make the values that over 0.5 zeros and the rest of the values keep them without any changes.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Chris il 15 Set 2022
Modificato: Chris il 15 Set 2022
If there's a single value in each cell, you could first convert to a matrix.
A = num2cell(rand(3))
A = 3×3 cell array
{[0.2044]} {[0.1296]} {[0.9499]} {[0.3952]} {[0.7477]} {[0.1062]} {[0.9799]} {[0.7201]} {[0.6477]}
Amat = cell2mat(A);
Amat(Amat>.5) = 0;
A = num2cell(Amat)
A = 3×3 cell array
{[0.2044]} {[0.1296]} {[ 0]} {[0.3952]} {[ 0]} {[0.1062]} {[ 0]} {[ 0]} {[ 0]}
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Walter Roberson il 15 Set 2022
newCell = cellfun(@(M) M.*(M<=0.5), YourCell, 'uniform', 0)
However this will fail in locations that contain infinite values.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by