Convert to fixed values and replace N/A with zero?

How do I convert this data to fixed values and replace N/A with zero?

6 comentarios

Rik
Rik el 6 de Jul. de 2022
What exactly do you mean by 'fixed values'?
dpb
dpb el 6 de Jul. de 2022
What happened to the previous Q? you raised? You haven't accepted/commented on our efforts there, yet...
@Rik Fixed as in real number.
dpb
dpb el 9 de Jul. de 2022
Editada: dpb el 9 de Jul. de 2022
It is a real number (default double) if read it in with any of the input routines expecting numeric values -- why would you do otherwise?
See the answer posted below...
@dpb I want to convert scienfic notations to real number.
dpb
dpb el 9 de Jul. de 2022
Specifically what format do you consider a "real" number? And where is this formatting to take effect -- at command line (see format for that) or writing an output file or...???

Iniciar sesión para comentar.

 Respuesta aceptada

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
2-Imported table data after reading
3-Fill missing values
4-Write updated values to file
Hope this helps.

4 comentarios

This has been very helpful. Thank you so much. Now, How do I find the maximum of the second column in the table?
Use the max function, maybe?
You would greatly benefit in getting started w/ MATLAB to spend some time reading the "Getting Started" section in the documentation and getting familiar with basic commands.
lookfor XXX
where "XXX" is a subject of interest is (like "max" here) is also a good way to see what's available on a given topic -- here it would look something like
>> lookfor max
getmaxk - wrapper for maxk cuz can't return second output w/ anonymous function
imax - Return max() indices as first argument
cummax - Cumulative largest component.
islocalmax - Detect local maxima in data.
max - Maximum elements of an array.
maxk - Return largest K elements from array
movmax - Moving maximum value.
flintmax - Largest consecutive integer in floating point format.
intmax - Largest positive integer value.
realmax - Largest finite floating point number.
maxNumCompThreads - controls the maximum number of computational threads
namelengthmax - Maximum length of MATLAB function or variable name.
nzmax - Amount of storage allocated for nonzero matrix elements.
max - Largest element in an ordinal categorical array.
maxk - Return largest K categories from input
max - Find maximum of datetimes.
maxk - Return largest K elements from input
movmax - Moving maximum value.
max - Find maximum of datetimes.
max - Find maximum of durations.
maxk - Find largest k duration
...
which can point you to functions that may be worth looking at specifically.
@dpb max function does not work for a table format. I had to covert it to cell using table2cell and then cell2mat to use the max function.
dpb
dpb el 9 de Jul. de 2022
Editada: dpb el 9 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (2)

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')
data = 30×1 string array
"id,value" "44, 0.000E+00" "526, 6.464E-03" "527, 0.000E+00" "529, 0.000E+00" "530, 6.332E-03" "532, 6.838E-03" "542, 0.000E+00" "886, 0" "887, 0" "888, 0" "889, 0" "890, 0" "891, 0" "892, 0" "893, 5.030E-03" "894, 0" "895, 7.226E-03" "896, 8.863E-03" "897, 0" "898, 7.015E-03" "899, 6.572E-03" "900, 0" "901, 0" "902, 6.896E-03" "903, 6.118E-03" "904, 0" "905, 0" "906, 0" "1047, 0.000E+00"

2 comentarios

Yes, it does. Thank you. I get 1 column with numbers of type string. How do I divide these into two columns?
dpb
dpb el 9 de Jul. de 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.

Iniciar sesión para comentar.

dpb
dpb el 6 de Jul. de 2022
As @Rik, I have no klew what fixed values are to be, but the other Q? is trivial --
  1. Brute force...
data=readtable('micro.txt');
data.value(isnan(data.value))=0;
2. Use builtin paramters on input...
data=readtable('micro.txt',"EmptyValue",0);

Categorías

Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Jul. de 2022

Comentada:

dpb
el 9 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by