I Want to change the last column of a cell 25*5 from characters ie {'Fd,Fc,Fb,Fr'} to numbers, [1,2,3,4]. the code must find for Ex. Fd and replace it with 1 and so on.Thanks
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a cell 1*11 inside which there is 11 cells of dimensions 25*5.I Want to change the last column of a cell 25*5 from characters ie {'Fd,Fc,Fb,Fr'} to numbers, [1,2,3,4]. the code must find for -Ex. Fd and replace it with 1 and so on...
2.27000000000000 240.200000000000 49.6100000000000 0 'Fd'
2.45000000000000 214.610000000000 37.8800000000000 0 'Fd'
4.52000000000000 143.200000000000 6.41000000000000 0 'Fc'
4.60000000000000 51.9000000000000 51.5500000000000 0 'Fc'
4.69000000000000 48.3800000000000 54.9000000000000 0 'Fd'
4.74000000000000 55.0400000000000 24.9100000000000 0 'Fd'
Can someone please help.
Thank you
0 commentaires
Réponses (1)
Voss
le 30 Avr 2022
You can do this for each of the 11 cells:
C = { ...
2.27000000000000 240.200000000000 49.6100000000000 0 'Fd'
2.45000000000000 214.610000000000 37.8800000000000 0 'Fd'
4.52000000000000 143.200000000000 6.41000000000000 0 'Fc'
4.60000000000000 51.9000000000000 51.5500000000000 0 'Fc'
4.69000000000000 48.3800000000000 54.9000000000000 0 'Fd'
4.74000000000000 55.0400000000000 24.9100000000000 0 'Fd'};
lookup = {'Fd' 'Fc' 'Fb' 'Fr'};
[ism,idx] = ismember(C(:,end),lookup);
C(ism,end) = num2cell(idx(ism));
disp(C)
M = cell2mat(C) % now (maybe) C can be made into a numeric matrix
4 commentaires
Voss
le 30 Avr 2022
If you get some values of idx equal to 0 it means some elements of C(:,end) are not in the set of characters lookup, so make sure you are using the right set of characters, because you mentioned these in the question:
{'Fd' 'Fc' 'Fb' 'Fr'}
Then you said it's these:
{'Fd' 'Fc' 'Fo' 'Fr'}
(note the 'Fo' instead of 'Fb')
And make sure they're in the right order, because in your last comment you said "instead of Fr put 3", but 'Fr' is 4th.
Voir également
Catégories
En savoir plus sur Get Started with MATLAB 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!