I am trying to store every value into a 1D Array from a for loop

Tried to have the value Phiij in a (1,9) array from a for loop. Tried multiple things.
function [viscosity,Phiij] = project2m(Chemical1,Chemical2,Chemical3)
M = [Chemical1(2), Chemical2(2), Chemical3(2)] %molec weight array
mu = [Chemical1(3), Chemical2(3), Chemical3(3)] %viscosity array
MF = [Chemical1(1), Chemical2(1), Chemical3(1)] %molar fraction
ArrayPhi = zeros(1,9);
for i = 1:3
for j = 1:3
if i ~= j
Phiij = (1/sqrt(8))*((1+(M(i)/M(j)))^(-.5))*(1+((mu(i)/mu(j))^.5)*((M(j)/M(i))^.25))^2
else Phiij = 1
end
end
end
for i = 1:3
X1 = (MF(i) * ArrayPhi(i)) % this isnt working because of index error
viscosity = 0;
end

Answers (1)

It's difficult to tell exactly what you are trying to do, but perhaps the following is close to what you want:
ArrayPhi = zeros(3,3);
for i = 1:3
for j = 1:3
if i ~= j
Phiij = (1/sqrt(8))*((1+(M(i)/M(j)))^(-.5))*(1+((mu(i)/mu(j))^.5)*((M(j)/M(i))^.25))^2;
else
Phiij = 1;
end
ArrayPhi(i,j) = Phiij;
end
end
X1 = MF * ArrayPhi;

This question is closed.

Asked:

on 8 Sep 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!