how to add and sort a cell with a string in a cell array in order to replace or add a cell with respect the last word of the cell?
Show older comments
I did this using a lot of lines and I was wondering if you could recommend me a better way to do it.
I have a predefined cell array and I'm constantly generating new data that I have to add or replace in the cell array and sorted regarding the last word of the cell.
Let's say I have a cell array A like:
A{1, 1} = 'whatever - a';
A{2, 1} = 'doesNotMatter - b';
A{3, 1} = 'not even with spaces - d';
A{4, 1} = 'blablabla - ee';
if I have these new cells to add in my array
newCell1 = 'thanksForHelping - c';
newCell2 = 'I really appreciate it - ee';
I would like to add newCell1 (since "c" is not in the original) and replace newCell2 with the one in A{4, 1} (since "ee" is there)
so at the end, I can obtain something like:
A =
5×1 cell array
'whatever - a'
'doesNotMatter - b'
'thanksForHelping - c'
'not even with spaces - d'
'I really appreciate it - ee'
I know that the ideal thing will be to change the data to "a - whatever" and use a simple sort but it is not possible to change the final format.
Could you recommend me something?
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion 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!