Write multiple variables from a function

3 ビュー (過去 30 日間)
Martyn Steel
Martyn Steel 2022 年 8 月 5 日
回答済み: Star Strider 2022 年 8 月 5 日
I'm aware this is probably a horribly inefficient way of completing my work. What I'm trying to do is run through a workflow with a variety of different permutations of variables and get the large range of outputs for me to analyse.
What I've wrote up so far is:
% Define the CO2 Saturation sampling percentages (every 0.5%)
sat_samp_int=linspace(0,1,200);
% Generate the various saturation logs for the different scenarios
sw_sats=Sw*sat_samp_int;
co2_sats=CO2_Sat*sat_samp_int;
% Loop through the different saturations
for i = 1:200
qq1=sw_sats(:,i)./k_brine;
qq2=co2_sats(:,i)./Kb.';
end
In essence, I want to be able to generate the 200 different scenarios but I think the way I'm writing this so far is that each iteration is overwriting the previous loop so I'm only left with the output with reference to the final column of "sw_sats" and "co2_sats".
Is there a way to implement it so that I can actually be left with all my different iterations visible for me to view? Even if it leaves me with a massive array that is workable for me.
  5 件のコメント
Martyn Steel
Martyn Steel 2022 年 8 月 5 日
Hi Star Strider,
I fully think your logic of just making everything the same shape is actually just going to be my best approach moving forwards.
Thank you for the response!
Star Strider
Star Strider 2022 年 8 月 5 日
My pleasure!
I’ll post it as an Answer now, as well.

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

採用された回答

Star Strider
Star Strider 2022 年 8 月 5 日
sw_sats is a 7071x200 array
co2_sat is 7071x200 array
k_brine is a 1x1500 array
Kb is a 1x1500 array
That means that ‘Sw’ and ‘CO2_Sat’ are (7071 x 1) vectors. Make this straightforward with:
sat_samp_int=linspace(0,1,1500);
and they are now instead (7071 x 1500) matrices. With that, everything has compatible dimensions and straightforward matrix division is possible.
qq1=sw_sats./k_brine;
qq2=co2_sats./Kb;
Make appropriate transpose or reshape operations to get the result you want (since I have no idea what that is).
.

その他の回答 (1 件)

James Tursa
James Tursa 2022 年 8 月 5 日
編集済み: James Tursa 2022 年 8 月 5 日
Maybe something like this does what you want, with each qq1 and qq2 2D page results in the first two dimensions.
[m n] = size(sw_sats);
qq1 = reshape(sw_sats,m,1,n) ./ k_brine;
qq2 = reshape(co2_sats,m,1,n) ./ Kb;
That is,
qq1(:,:,1) would be the result of sw_sats(:,1) ./ k_brine
qq1(:,:,2) would be the result of sw_sats(:,2) ./ k_brine
qq2(:,:,1) would be the result of co2_sats(:,1) ./ Kb
qq2(:,:,2) would be the result of co2_sats(:,2) ./ Kb
etc.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by