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?

 채택된 답변

Ingrid
Ingrid 2016년 1월 5일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2016년 1월 5일

댓글:

2016년 1월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by