3D matrix from 2D matrix multiplied by 1D array
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a 26 by 5 matrix and want to perform an operation via a 1D array of four entries as follows:
% constants
par_a = {0.043 0.0586 0.1344 0.2056};
par_b = {0.74 0.72 0.66 0.63};
divnum2 = 25;
X2=xo:((xf-xo)/divnum2):xf;
N3 = length(X2);
for i6 = 1:N3
x = X2(i6);
% radial coordinate
r = x*b;
% Rephi calculation at each interval
for i4 = 1:N2
Re_Phi {i6,i4} = (omega{i4}*(r^2))/nu;
end
end
Re_phi = cell2mat(Re_Phi);
for i6 = 1:N3
for i2 = 1:length(Ctflow)
Nu_r{i2} = par_a{i2} * (Re_phi.^par_b{i2});
end
end
However I am being met with this error:
Unable to perform assignment because brace indexing is not supported for variables of this type.
How can I go abot it and how can I then call a row or column of values from the resulting 3D matrix??
댓글 수: 0
채택된 답변
Voss
2022년 2월 20일
My guess is that Re_Phi and/or Nu_r are matrices before this code is run
Re_Phi = magic(4)
omega = {1};
Re_Phi {1,1} = (omega{1}*(1^2))/1
To avoid this error, you can intialize them as cell arrays of appropriate size before the loops that fill them with values, using the cell() function, e.g.:
% constants
par_a = {0.043 0.0586 0.1344 0.2056};
par_b = {0.74 0.72 0.66 0.63};
divnum2 = 25;
X2=xo:((xf-xo)/divnum2):xf;
N3 = length(X2);
% initialize Re_phi
Re_Phi = cell(N3,N2);
for i6 = 1:N3
x = X2(i6);
% radial coordinate
r = x*b;
% Rephi calculation at each interval
for i4 = 1:N2
Re_Phi {i6,i4} = (omega{i4}*(r^2))/nu;
end
end
Re_phi = cell2mat(Re_Phi);
% initialize Nu_r
Nu_r = cell(1,length(Ctflow));
for i6 = 1:N3 % not sure what this loop is for; nothing inside seems to depend on i6
for i2 = 1:length(Ctflow)
Nu_r{i2} = par_a{i2} * (Re_phi.^par_b{i2});
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!