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

5 次查看(过去 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??

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by