Would like to create a 2x3 matrix using for loop

6 ビュー (過去 30 日間)
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 14 日
編集済み: Matt J 2020 年 4 月 14 日
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.

採用された回答

Matt J
Matt J 2020 年 4 月 14 日
編集済み: Matt J 2020 年 4 月 14 日
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.
  1 件のコメント
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 14 日
Thank you! Got it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by