Convert to fixed values and replace N/A with zero?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I convert this data to fixed values and replace N/A with zero?
6 commentaires
Réponse acceptée
Pratyush Swain
le 6 Juil 2022
I believe by "converting to fixed number" you are trying to convert the scientic notation to real number notation.
%read the data%(This automatically coverts the numbers from scientic notation to floating point)
data=readtable("micro.txt");
%fill missing data%
data=fillmissing(data,'constant',0);
%write the table data to new file%
writetable(data,'micro_new.txt');
So the above 3 lines entails the following process
1-Sample Data
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1057125/image.png)
2-Imported table data after reading
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1057130/image.png)
3-Fill missing values
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1057135/image.png)
4-Write updated values to file
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1057140/image.png)
Hope this helps.
4 commentaires
dpb
le 9 Juil 2022
Modifié(e) : dpb
le 9 Juil 2022
Nonsense. Read the doc on referencing table variables. See <table> and <Access Data in Tables>, the latter is a link in the preceding doc for table that shows how to use one once you have it.
You really wouldn't think TMW would build the table class and have no way in which to reference it, would you? There is a "veritable plethora" of addressing options and additional functionality associated with the table and timetable classes--but you've got to spend a little effort on your own and read/study the documentation for syntax and then look at the example code for illustration and to get an idea about some of the features that are therein.
And, don't overlook the links at the top of the doc page on Functions and the See Also section at the bottom of the page that shows you the most closely related other functions you're likely to find useful if you're using the specific function.
Plus de réponses (2)
Rik
le 6 Juil 2022
Perhaps the strrep function does what you need.
data=readlines('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1057030/micro.txt');
data=data(1:30);
data=strrep(data,'N/A',' 0')
2 commentaires
dpb
le 9 Juil 2022
Read the data file as numeric to begin with and you won't need to.
But, we just solved that problem in the other topic -- "split" if there were some real reason (hard to imagine what it would be) to read as text.
You can always write the numeric data back out in text files; there's no sense in making working with numeric data in memory more difficult than needs be.
dpb
le 6 Juil 2022
- Brute force...
data=readtable('micro.txt');
data.value(isnan(data.value))=0;
2. Use builtin paramters on input...
data=readtable('micro.txt',"EmptyValue",0);
0 commentaires
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!