필터 지우기
필터 지우기

3D matrix from 2D matrix multiplied by 1D array

조회 수: 2 (최근 30일)
Karl Zammit
Karl Zammit 2022년 2월 19일
댓글: Karl Zammit 2022년 2월 20일
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??

채택된 답변

Voss
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)
Re_Phi = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
omega = {1};
Re_Phi {1,1} = (omega{1}*(1^2))/1
Unable to perform assignment because brace indexing is not supported for variables of this type.
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
  댓글 수: 1
Karl Zammit
Karl Zammit 2022년 2월 20일
My bad, the i6 loop was theere for nothing as suggested. Thanks a lot !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by