Finding values in an Array

5 vues (au cours des 30 derniers jours)
Aldo Amaya
Aldo Amaya le 30 Jan 2014
Commenté : Aldo Amaya le 30 Jan 2014
If I have an array such as
Subject= [126;156;1992, 203, 186] % First two digits determine group, additional numbers are specific subject within that group.
Is there a method to only read the first two values of each row in order to determine what group the subject is?
Group= [12;15;19;20;18] %%%This is what I would like the result to be.

Réponse acceptée

Jos (10584)
Jos (10584) le 30 Jan 2014
Apply some arithmetic:
Subject = [126 156 1992 203 186 10 100 100000]
Group = fix(Subject ./ (10.^floor(log10(Subject)-1)))
  1 commentaire
Aldo Amaya
Aldo Amaya le 30 Jan 2014
Thank you, this worked perfectly :)

Connectez-vous pour commenter.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 30 Jan 2014
Group = floor(Subject ./ 10);
  1 commentaire
Aldo Amaya
Aldo Amaya le 30 Jan 2014
Thanks for the reply, the only issue is that they are not all the same number of elements. Subjects elements range from 3-5 currently.

Connectez-vous pour commenter.


Aldo Amaya
Aldo Amaya le 30 Jan 2014
Modifié(e) : Aldo Amaya le 30 Jan 2014
This was my solution but I wish there was a cleaner way to do it
Group = floor(Namex2 ./ 10);
i=1;
while i<=length(Group)
if Group(i)>=100
Group(i)=floor(Group(i)./ 10);
else
end
i=i+1;
end

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by