Azzera filtri
Azzera filtri

Shifting or sorting arrays with specific names

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Ingrid
Ingrid il 5 Gen 2016
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 Commenti
Praveen Choudhury
Praveen Choudhury il 5 Gen 2016
How do I shift to the end, having got the index?
Ingrid
Ingrid il 6 Gen 2016
cellArray(end,1) = cellArray(idx,1);
cellArray(idx,1) = [];

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by