Would like to create a 2x3 matrix using for loop

6 views (last 30 days)
pnh3=.046; %%torr
po2=.068; %%torr
R1=1.987 ; %%cal/gmol*K
R=62.364; %%torr L/gmol K
vo=100/3600; %%L/s
T=zeros(3,1);
T(1)=473;
T(2)=673;
T(3)=800;
z=Ljallo_f1_q1(T,R1,pnh3,po2);
fio=Ljallo_f2_q1(T,R,vo,pnh3,po2);
function iFlows=Ljallo_f2_q1(T,R,vo,pnh3,po2)
cnh3=zeros(3,1);
finh3o=zeros(3,1);
co2=zeros(3,2);
fio2o=zeros(3,2);
iFlows=zeros(3,2);
for i=1:3
cnh3(i,1)=pnh3/(R.*T(i));
finh3o(i,1)=cnh3(i,1).*vo;
iFlows=finh3o(i,1);
co2(i,2)=po2/(R.*T(i));
fio2o(i,2)=co2(i,2).*vo;
iFlows=fio2o(i,2);
end
>> Ljallo_s_q1
>> fio
fio =
3.7860e-08
>>
I want to create a 2x3 matrix for 'fio'. however, when I call it I get one anwser.

Accepted Answer

Matt J
Matt J on 14 Apr 2020
Edited: Matt J on 14 Apr 2020
This line has an error,
iFlows=fio2o(i,2);
The right hand side fio2o(i,2) is a scalar, but there is no indexing on the left hand side to tell where in iFlows it should be assigned to. So, the whole array iFlows simply gets overwritten.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!