MATLAB: How to link arrays to specific values in another array

if statement

Hi
So I've got a 960×1 array that looks like this: [1 4 5 2 3 7…] The numbers represent products, and each product is a combination of 3 ingredients, represented by 3 columns so for example: 1 = product one = 0.75X + 0.5Y + 0.20Z The combination of the ingrediĆ«nts differ for each product.
What I want to do is to link the specific combination of ingrediĆ«nts (the three columns) to each specific product, so matlab automatically returns 0.75 0.5 0.20 for product one, et cetera…
How can I do this? What code do I have to use?

Best Answer

Try
A = [0.75;0.3;0.3;0.1;0.1;0.1;0.33];
B = [0.15;0.6;0.15;0.1;0.1;0.1;0.33];
C = [0.1;0.1;0.55;0.1;0.1;0.1;0.33];
ingredientFractions = [A,B,C]
To access a particular product, whose index is the same as the row number:
productNumber = 2;
product2Fractions = ingredientFractions(productNumber,:)