How to export "Nan" and "inf" in a table from MATLAB to EXCEL as text?
34 views (last 30 days)
Show older comments
I created a code that generates a table "R" that has a column called "number" which has values including inf and NaN. I'm exporting this table into EXCEL. However, NaN shows as blank cell and inf shows as 65535. Is it possible to convert Nan and inf as text to EXCEL?
I was trying to add a for loop that checks for any inf and NaN in table and convert them to a string but I'm not able to do it correctly. Here is my attempt:
for y=1:10
R.number(isinf(R.number))= ;
R.number(isnan(R.number))= ;
end
writetable(R,'r.xlsx','Sheet',1);
Any help is appreciated!
0 Comments
Accepted Answer
Walter Roberson
on 15 Mar 2023
base = tempname;
cname = base + ".csv";
xname = base + ".xlsx";
A = [1; 2; 3; nan; inf];
writematrix(A, cname)
dbtype(cname)
B = readcell(cname)
writematrix(A, xname)
C = readcell(xname)
masknan = isnan(A);
maskinf = A == inf;
D = num2cell(A);
D(masknan) = {'NaN'};
D(maskinf) = {'Inf'};
writecell(D, xname)
E = readcell(xname)
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!