Home Replacing string values in cell array with numbers
Reply: 0

Replacing string values in cell array with numbers

user880
1#
user880 Published in May 24, 2018, 3:52 pm

I have a cell array which contains some descriptions, namely my_des.

 my_des = [{'FRD'} {'1'}; {'UNFRD'} {'2'}; {'OTH'} {'3'};];

I also have an approximately 5000x1 cell array. The elements in this array are either 'FRD', 'UNFRD' or 'OTH'.

What I want to do is replace these text values with the corresponding numeric values in my_des.

Currently my only idea (which I think isn't that great) is to loop through my_des and do a string replacement.


Example:

So say my current vector looks like this:

FRD
FRD
OTH
UNFRD
OTH
FRD

Then my desired output would be this:

1
1
3
2
3
1

The numbers come from the my_des array

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.414588 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO