4 views (last 30 days)
Show older comments
Opeyemi Kehinde on 5 Dec 2021
-
-
Link
Direct link to this question
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry
Commented: Opeyemi Kehinde on 10 Dec 2021
Accepted Answer: Walter Roberson
I have a 2160 by 4320 data that has lots of NaN. How do I make matlab ignore the NaNs (i.e making them an empty entry, not zero) and still maintain the same size of the data size
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Walter Roberson on 5 Dec 2021
Open in MATLAB Online
A=randi(500,5,5);
A(A<100)=nan
A = 5×5
138 207 415 446 134 NaN 437 153 NaN 449 119 443 141 127 NaN 294 235 NaN 336 149 NaN 155 235 314 264
Ac = num2cell(A)
Ac = 5×5 cell array
{[138]} {[207]} {[415]} {[446]} {[134]} {[NaN]} {[437]} {[153]} {[NaN]} {[449]} {[119]} {[443]} {[141]} {[127]} {[NaN]} {[294]} {[235]} {[NaN]} {[336]} {[149]} {[NaN]} {[155]} {[235]} {[314]} {[264]}
Ac(isnan(A)) = {[]}
Ac = 5×5 cell array
{[ 138]} {[207]} {[ 415]} {[ 446]} {[ 134]} {0×0 double} {[437]} {[ 153]} {0×0 double} {[ 449]} {[ 119]} {[443]} {[ 141]} {[ 127]} {0×0 double} {[ 294]} {[235]} {0×0 double} {[ 336]} {[ 149]} {0×0 double} {[155]} {[ 235]} {[ 314]} {[ 264]}
Ac is now the same size as A, but the nan entries have been made empty.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
More Answers (1)
Matt J on 5 Dec 2021
Open in MATLAB Online
It depends on the operation. If you are taking the maximum of each data colum, for example, the NaNs are already ignored, e.g.,
A=randi(500,5,5);
A(A<100)=nan
A = 5×5
156 367 474 104 134 395 166 128 NaN 108 478 360 196 392 387 160 150 NaN 439 190 336 NaN 219 148 330
maximum = max(A)
maximum = 1×5
478 367 474 439 387
6 Comments Show 4 older commentsHide 4 older comments
Show 4 older commentsHide 4 older comments
Opeyemi Kehinde on 5 Dec 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry#comment_1870040
⋮
I want to create a new variable of the same size and data but this new variable should show blanks/nothing in the places where nan occured. Something like find(isnan(var))=[]
Matt J on 6 Dec 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry#comment_1870080
No, you can't do that. Some place holder to mark missing data will be present in any Matlab array type.
Walter Roberson on 6 Dec 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry#comment_1870180
Well it can be done if it is intended for display only, by constructing a character array and disp() that.
Opeyemi Kehinde on 8 Dec 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry#comment_1875365
Thanks for the help, but I don't think I can use it for a mathematical calculation (maybe multiplying with another matching data) in this cell format or plot a graph.
Walter Roberson on 8 Dec 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry#comment_1875625
Suppose that somehow you were able to create a numeric-like matrix that you could do mathematics with, and yet displayed some elements as blanks/nothing. What mathematical properties should be blank/nothing have? For example should [blank*2,5] have the blank be treated as the empty vector, and empty times 2 is empty, and horzcat([], 5) is the scalar 5 ??
Opeyemi Kehinde on 10 Dec 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/1603735-how-to-make-nan-data-an-empty-entry#comment_1879655
Ok thanks
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABLanguage FundamentalsMatrices and ArraysResizing and Reshaping Matrices
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Tags
- nan
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office