Replacing numbers in dataset by string
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Radoslav Vandzura
le 30 Jan 2016
Commenté : Radoslav Vandzura
le 30 Jan 2016
Hello, could you help me please with this code:
for i=1:length(inoperationDatatree1.SystemSlices)
if (inoperationDatatree1.SystemSlices(i)>0 && inoperationDatatree1.SystemSlices(i)<=50)
inoperationDatatree1.SystemSlices(i)={'<=50'};
elseif (inoperationDatatree1.SystemSlices(i)>51 && inoperationDatatree1.SystemSlices(i)<=100)
inoperationDatatree1.SystemSlices(i)={'50...100'};
elseif (inoperationDatatree1.SystemSlices(i)>101 && inoperationDatatree1.SystemSlices(i)<=150)
inoperationDatatree1.SystemSlices(i)={'101...150'};
else inoperationDatatree1.SystemSlices(i)={'>150'};
end
end
I need to replace each of row by interval...
2 commentaires
David Young
le 30 Jan 2016
Storing those strings is an unusual thing to want to do. Can you explain what the purpose is, because there might be a much better way to solve the underlying problem.
Réponse acceptée
John BG
le 30 Jan 2016
Quoting from Mathworks documentary: http://uk.mathworks.com/help/stats/dataset-class.html?s_tid=srchtitle
.. The dataset data type might be removed in a future release. To work with heterogeneous data, use the MATLAB® table data type instead. See MATLAB table documentation for more information ..
you seem to be attempting to cast a string in the place that you initially allocated to a number. If you had a cell, that would be fine, you can even replace numbers with entire arrays, or nesting cells inside cell positions.
why don't you translate your dataset into a table and start replacing table elements from there?
The Mathworks documentary starter example:
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(Age,Height,Weight,BloodPressure,'RowNames',LastName)
pull some table elements with
T(1,1)
ans =
Age
_____
Smith 38.00
or
T(3,4)
T(3,4)
ans =
BloodPressure
________________
Williams 125.00 83.00
Yet T(1,1)='38' does not work either
but if you convert your table to a cell
Tcell=table2cell(T)
Now you can modify any field of the cell, you can have numbers next to strings in neighbouring cell fields.
Now mind the gap:
Tcell_1_1=Tcell(1,1)
Tcell_1_1 is still a cell
if you try Tcell(1,1)='38' doesn't work but the following works:
Tcell{1,1}='38'
Check
Tcell
and you see all Tcell fields containing cells but the (1,1) field where you just cast in a string.
Hope it helps, if so please click on thumbs up
John
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Preprocessing 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!