How do I edit certain cells of a cell-array with a logical index (without using for-loops)
Show older comments
Hi everyone,
lets say I have a cell array and a numeric array like:
Old_Array = {20 , '2' ; 21 , '2' ; 22 , '2,3' ; 25 , '3' ; 28 , '2'};
and
new_Numbers = [18 ; 21 ; 22 ; 32];
What I want, is to some kind of mix those two. If a number of new_Numbers matches with the first column of old_Array, i want to add '4' to the cell in the 2nd column on just that row. If a number of new_Numbers is not matched, i want to add it, with the 2nd column containing the'4' String. The result should look like
New_Array = {18 , '4' ; 20 , '2' ; 21 , '2,4' ; 22 , '2,3,4' ; 25 , '3' ; 28 , '2' ; 32 , '4'};
I wonder if there is a solution not using for loops but [i,j]=ismember(new_Numbers,cell2mat(Old_Array(:,1))) and the logical indexes.
Thanks in advance. Any Help is appreciated! :)
1 Comment
Mr Anderson
on 12 Dec 2015
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!