Replacing numbers in dataset by string

조회 수: 3 (최근 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개)

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by