Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Karl Zammit
Karl Zammit el 19 de Feb. de 2022
Comentada: Karl Zammit el 20 de Feb. de 2022
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??

Respuesta aceptada

Voss
Voss el 20 de Feb. de 2022
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 comentario
Karl Zammit
Karl Zammit el 20 de Feb. de 2022
My bad, the i6 loop was theere for nothing as suggested. Thanks a lot !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by