Save array in matrix from for loop

4 vues (au cours des 30 derniers jours)
Karl Zammit
Karl Zammit le 11 Déc 2021
Commenté : Karl Zammit le 12 Déc 2021
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

Réponse acceptée

KSSV
KSSV le 11 Déc 2021
Modifié(e) : KSSV le 11 Déc 2021
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 commentaire
Karl Zammit
Karl Zammit le 12 Déc 2021
The first method worked just fine thanks. The second method no.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by