Replacing numbers in dataset by string

2 ビュー (過去 30 日間)
Radoslav Vandzura
Radoslav Vandzura 2016 年 1 月 30 日
コメント済み: Radoslav Vandzura 2016 年 1 月 30 日
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 件のコメント
David Young
David Young 2016 年 1 月 30 日
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.
Radoslav Vandzura
Radoslav Vandzura 2016 年 1 月 30 日
I want to do classification tree and before that i need adapt (modify) my dataset for that....

サインインしてコメントする。

採用された回答

John BG
John BG 2016 年 1 月 30 日
.. 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 件のコメント
Radoslav Vandzura
Radoslav Vandzura 2016 年 1 月 30 日
But, when i have table yet, how can I do it in a cycle? Because I have many rows...how can i scan the entire table...?
Radoslav Vandzura
Radoslav Vandzura 2016 年 1 月 30 日
I did it yet, thank you very very much, I really appreciate your help and time :)

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by