Effacer les filtres
Effacer les filtres

String selection from Matrix data

2 vues (au cours des 30 derniers jours)
JB
JB le 10 Oct 2017
Commenté : JB le 10 Oct 2017
Hi guys. I need a little help from you Matlab experts.
I have a cell array (Names) with a list of 14 different names. Then I have a 15x3 matrix (Selection) with some random numbers from 0-14.
Now what I want to do is use each row in the "selection" matrix to make a list of names corresponding to the number in each cell. As an example the first row is [1 3 12] shall make thes list of names {Dave Smith Niko}. The third row is [9 2 0] and should result in the list {Chris Andy}.
It's ok to get the name list's out in a combined 15x3 cell array for instance from a loop.
PLEASE help me sort this out. Thanks
Names = {
'Dave'
'Andy'
'Smith'
'Eric'
'Donna'
'Lisa'
'Gawin'
'Bill'
'Chris'
'Crystal'
'Beth'
'Niko'
'Conny'
'Clara'
}
Selection = [
1 3 12;
3 6 8;
9 2 0;
4 2 1;
8 5 7;
3 2 0;
4 7 1;
4 9 12;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
]

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 10 Oct 2017
Modifié(e) : Andrei Bobrov le 10 Oct 2017
Names(end+1) = {'none'};
Selection(Selection == 0) = numel(Names);
out = Names(Selection);
or
out = cellfun(@(x)reshape(Names(x(x~=0)),1,[]),num2cell(Selection,2),'un',0);
  1 commentaire
JB
JB le 10 Oct 2017
Great. Thanks a lot Andrei Bobrov

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by