how to transfer a cell array content into ordinal values?
Mostrar comentarios más antiguos
i have a cell array of string content and i want to turn the contents of cell 2 into ordinal values according to the list shown below in 'clinicalVAL.png'
catnames = { 'stage i'; 'stage ia'; 'stage ii'; 'stage iia'; 'stage iib'; 'stage iic'; 'stage iii'; 'stage iiia';'stage iiib'; 'stage iiic'; 'stage iv'; 'stage iva'; 'stage ivb'};
valueset={1;2;3;4};
for i=1:217
B = categorical(Ystg{i}(2),catnames,valueset,'Ordinal',true);
end
I have tried this code but doesn't work and i want to do it programmatically and not manually; is it possible in MATLAB?
ERROR: Error using categorical
Creating an instance of the Abstract class 'categorical' is not allowed.
Respuesta aceptada
Más respuestas (2)
Jan
el 9 de Abr. de 2017
Or simpler:
for i=1:217
switch Ystg{i}(2)
case {'stage i', 'stage ia'}
Stage(i,1) = 1;
case {'stage ii', 'stage iia', 'stage iib', 'stage iic'}
Stage(i,1) = 2;
case {'stage iii', 'stage iiia', 'stage iiib', 'stage iiic'}
Stage(i,1) = 3;
case {'stage iv', 'stage iva', 'stage ivb'}
Stage(i,1) = 4;
otehrwise % No switch without otherwise!
error('Unexpected value!');
end
1 comentario
chocho
el 10 de Abr. de 2017
>> C = vertcat(Ystg{:});
>> D = strcat('\s(',{'i','ii','iii','iv'},')[a-d]?$');
>> E = cellfun(@(s)regexp(C(:,2),s,'once'),D,'Uni',0);
>> [F,~] = find(~cellfun('isempty',horzcat(E{:})).')
F =
3
3
2
2
2
2
3
2
1
2
1
3
2
1
3
3
3
4
4
2
2
3
3
...etc
1 comentario
chocho
el 10 de Abr. de 2017
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!