Puzzler for a Monday
5 ビュー (過去 30 日間)
古いコメントを表示
Given a cell array of strings
A = {'MATLAB','HURRAY','SPARKLY','KITTENS','FUN'};
and a particular string value
B = 'KITTENS';
ensure that B is the last element of the cell array. If it isn't, move it to the end of A.
You cannot assume that B appears at all (in which case return A unchanged), but you can assume B does not appear more than once.
[I have a solution, but I post this as a puzzle because I bet someone can find a slicker one.]
0 件のコメント
回答 (6 件)
Abdullah Caliskan
2015 年 1 月 27 日
k=ismember(A,B) A(k)='' if sum(k)==0 A=A; else A=[A B] end
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!