Puting empty value in numeric array
Afficher commentaires plus anciens
Easy question for advanced users, big question for a beginner like me.
I want to put an empty value or no value into a numeric matrix.
As an example;
if true
for n=1:4;
If %some condition is satisfied%
Data(n,1)= % a numeric value like 4%
Else
Data(n,1)= % put nothing in this row %
end
End
end
Something like this,
Data(1,1)=3
Data(2,1)=4
Data(3,1)= no value,it exist but no value in it
Data(4,1)=5
Réponse acceptée
Plus de réponses (1)
Ugur Acar
le 9 Oct 2019
0 votes
4 commentaires
Steven Lord
le 9 Oct 2019
If you put NaN values in your array, you can try to fill them in later using the fillmissing function.
Ugur Acar
le 9 Oct 2019
meghannmarie
le 9 Oct 2019
Modifié(e) : meghannmarie
le 9 Oct 2019
When you use sum or any other statistics use the nan flag if you do not want those considered:
S = sum(Data, 'omitnan')
if you want to interpolate at the nan values, you can get of an index to all the nan values by using isnan and using interp1:
nan_idx = isnan(Data);
x = 1:numel(Data);
Data(nan_idx) = interp1(x(~nan_idx), Data(~nan_idx),x(nan_idx));
Ugur Acar
le 9 Oct 2019
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!