MATLAB Answers

0

Shifting or sorting arrays with specific names

Asked by Praveen Choudhury on 5 Jan 2016
Latest activity Commented on by Ingrid
on 6 Jan 2016
I have a cell array of 1000*1 dimension with names on it. I want to shift my elements in such a way that the name starting with N and ending with CA goes to the end. How can I do it?

  0 Comments

Sign in to comment.

1 Answer

Answer by Ingrid
on 5 Jan 2016
 Accepted Answer

you could use arrayfun to extract the first and last two letters and then use strfind to locate the index at which the letters that you want and then use this index for the shifting
firstLetter = arrayfun(@(n) cellArrayNames{n}(1),1:size(cellArrayNames,1),'UniformOutput',0);
lastTwoLetters = arrayfun(@(n) cellArrayNames{n}(end-2:end),1:size(cellArrayNames,1),'UniformOutput',0);

  2 Comments

How do I shift to the end, having got the index?
cellArray(end,1) = cellArray(idx,1);
cellArray(idx,1) = [];

Sign in to comment.