I am using cell array a with value like below
a = {'one' , 'two' ; 'four','five'};
now I am just compare the a with some string like 'two' and after then i just add another one column in a and insert string in that place
a{strcmp(a,'two'),3} ='Three' ;
I am getting output like below
a =
'one' 'two' []
'four' 'five' []
[] [] 'Three'
but actually I want output like below
a =
'one' 'two' 'Three'
'four' 'five' []
How can I do this?
Have you considered using maps for your task?
%// create map
keySet = {'one', 'two', 'three', 'four', 'five', 'six','seven','eight'};
valueSet = [1, 2, 3, 4, 5, 6, 7 ,8];
mapObj = containers.Map(keySet,valueSet);
%// data
a = {'one' , 'two' ; 'four', 'five'};
%// analyze data
Nums = cell2mat(values(mapObj,a));
%// expand data
Nums(:,3) = Nums(:,2) + 1
%// output
output = keySet(Nums)
output =
'one' 'two' 'three'
'four' 'five' 'six'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With