フィルターのクリア

Save array in matrix from for loop

2 ビュー (過去 30 日間)
Karl Zammit
Karl Zammit 2021 年 12 月 11 日
コメント済み: Karl Zammit 2021 年 12 月 12 日
I am trying to save two arrays (called pstar A and pstarB) in matrix form such that I can than plot each value as a point against the value of x, however, I am being presented with the error "Unable to perform assignment because the left and right sides have a different number of elements."
Any clues on how to do so and how to obtain the plot thereafter?
for x=xo:((xf-xo)/divnum):xf
% radial coordinate
rA = x*bA;
rB = x*bB;
% pressure due to rotation and radial variability
pabsA = (rho*(swirl^2)*(omegaA^2)*((rA^2)-(r0A^2))/2)-((rho*(avolflowA.^2))/(8*(pi^2)*(sA^2)*((rA^2)-(r0A^2))));
pabsB = (rho*(swirl^2)*(omegaB^2)*((rB^2)-(r0B^2))/2)-((rho*(avolflowB.^2))/(8*(pi^2)*(sB^2)*((rB^2)-(r0B^2))));
% pstar
pstarA = pabsA / (rho*(omegaA^2)*(bA^2));
pstarB = pabsB / (rho*(omegaB^2)*(bB^2));
psA = [pstarA, psA+1];
psB = [pstarB, psB+1];
counter = counter+1;
end

採用された回答

KSSV
KSSV 2021 年 12 月 11 日
編集済み: KSSV 2021 年 12 月 11 日
X=xo:((xf-xo)/divnum):xf
N = length(X) ;
pstarA = cell(N,1) ;
pstarB = cell(N,1) ;
for i = 1:N
x = X(i) ;
% radial coordinate
rA = x*bA;
rB = x*bB;
% pressure due to rotation and radial variability
pabsA = (rho*(swirl^2)*(omegaA^2)*((rA^2)-(r0A^2))/2)-((rho*(avolflowA.^2))/(8*(pi^2)*(sA^2)*((rA^2)-(r0A^2))));
pabsB = (rho*(swirl^2)*(omegaB^2)*((rB^2)-(r0B^2))/2)-((rho*(avolflowB.^2))/(8*(pi^2)*(sB^2)*((rB^2)-(r0B^2))));
% pstar
pstarA{i} = pabsA / (rho*(omegaA^2)*(bA^2));
pstarB{i} = pabsB / (rho*(omegaB^2)*(bB^2));
end
Also try:
X=xo:((xf-xo)/divnum):xf
N = length(X) ;
pstarA = zeros(N,1) ;
pstarB = zeros(N,1) ;
for i = 1:N
x = X(i) ;
% radial coordinate
rA = x*bA;
rB = x*bB;
% pressure due to rotation and radial variability
pabsA = (rho*(swirl^2)*(omegaA^2)*((rA^2)-(r0A^2))/2)-((rho*(avolflowA.^2))/(8*(pi^2)*(sA^2)*((rA^2)-(r0A^2))));
pabsB = (rho*(swirl^2)*(omegaB^2)*((rB^2)-(r0B^2))/2)-((rho*(avolflowB.^2))/(8*(pi^2)*(sB^2)*((rB^2)-(r0B^2))));
% pstar
pstarA(i) = pabsA / (rho*(omegaA^2)*(bA^2));
pstarB(i) = pabsB / (rho*(omegaB^2)*(bB^2));
end
  1 件のコメント
Karl Zammit
Karl Zammit 2021 年 12 月 12 日
The first method worked just fine thanks. The second method no.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by