Replace numbers by strings
Show older comments
Hi,
I have a matrix A= 1x100, and now I want to replace if numbers in A < 90 by 'case1' and A>=90 by 'case 2'
Could anyone offer some help?
Thanks
2 Comments
per isakson
on 14 Jan 2018
Strings, e.g. 'case1', cannot be stored in a numerical matrix.
Stephen23
on 14 Jan 2018
I mean probably I have to create a matrix B 1x100 which contains strings: 'case1' and 'case 2'. For example:
A B
10 case 1
100 case 2
40 case 1
.. so on
But I don't know how to a new matrix B according to numbers in matrix B.
More help please
Accepted Answer
More Answers (1)
Jan
on 14 Jan 2018
Or:
Pool = {'case1', 'case2'};
B = Pool((A < 90) + 1)
Or:
B = sprintfc('case%d', (A < 90) + 1)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!