Save array in matrix from for loop
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!