MATLAB: Replace numbers by strings

replace string

Hi,
I have a matrix A= 1×100, 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

Best Answer

One way:
A = randi([80,100], 1,100 ); % Sample data
C = cell(size(A));
C(A<90)={'case1'};
C(A>=90)={'case2'};
result
>> C(1:5)
ans =
'case1' 'case2' 'case2' 'case2' 'case1'