Multi-conditional statements for array lookup (similar to multi-conditional vlookup from Excel)
Afficher commentaires plus anciens
I have a matrix which lists a 'class' and a 'thickness' of a material, i.e.:
% A = [class thickness]
A = [p 1.2;
c 1.8;
b 0.5;
p 2.6;
p 0.8;
c 1.0;
p 1.2
c 8.0
p 1.8];
I have a second matrix which lists the attributes of each class, split into thickness ranges, i.e.:
% B = [class min_t max_t att1 att2 att3 att4 att5]
B = [b 0.1 1.0 10 0.1 9.2 1.4 1.8;
b 1.01 10.0 8 0.08 1.8 2.8 1.0;
c 0.1 10.0 7 0.7 5.6 2.0 1.1;
p 0.1 1.0 8 0.2 8.0 1.7 1.9;
p 1.01 1.1 6 0.09 1.9 1.1 0.8;
p 1.11 2.0 10 0.4 2.8 0.8 1.2];
What I am trying to do is to generate a matrix, C, which steps through each row of A, finds the corresponding match in B, and then lists the attributes. So in effect it has to checking that (a) the class character is the same, and (b) the thickness is within the min-max range specified in matrix B. So the solution should look like this:
% C = [class thickness att1 att2 att3 att4 att5]
C = [p 1.2 10 0.4 2.8 0.8 1.2;
c 1.8 7 0.7 5.6 2.0 1.1;
etc
I can't work out an efficient way to do it without a whole bunch of loops. Any suggestions would be much appreciated.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!