# How to create an empty array to be filled?

1.396 visualizaciones (últimos 30 días)
Ezgi Polat el 18 de Mayo de 2020
Comentada: Steven Lord el 23 de Sept. de 2022
Hi everyone,
I have this:
Ma=[];
d=yq1-yq1;
A=pi*(d.*d)/4;
mdot=(A.*Ma*P0*sqrt(k/(R*T0)))/(1+(k-1)*Ma^2/2)^((k+1)/(2*(k-1)));
(I highlighted important part)
A is a 1x100 array and I need Ma is to be 1x100 vector too. But I got this error:
Error using .*
Matrix dimensions must agree.
How can I create an empty 1x100 Ma array which will be calculated with the equation above?
All helps are appriciated!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Steven Lord el 18 de Mayo de 2020
What value or values do you want to be stored in Ma before that line of code executes?
Take a look at the list of functions in the "Create and Combine Arrays" section and the "Creating, Concatenating, and Expanding Matrices" Topic on this documentation page for some functions that may be useful in defining your Ma vector.
##### 2 comentariosMostrar NingunoOcultar Ninguno
Ezgi Polat el 18 de Mayo de 2020
Actually my aim to compute the values for Ma and then store them in the matrix. Other then Ma every other variables have specific values so there must be only one Ma matrix for those values.
Steven Lord el 18 de Mayo de 2020
Call fzero once per element of the variables that you know that are not scalars (1-by-1) to solve mdot-(A.*Ma*P0*sqrt(k/(R*T0)))/(1+(k-1)*Ma^2/2)^((k+1)/(2*(k-1))) = 0 for Ma.
Alternately if you have Symbolic Math Toolbox you could solve the system(s) symbolically for Ma as a function of a symbolic variable A then use subs to substitute the array of values for A into the symbolic solution.

Iniciar sesión para comentar.

### Más respuestas (3)

TADA el 18 de Mayo de 2020
Ma is a 0x0 empty vector:
Ma = []
Ma =
[]
You can't multiply your 1x100 vector A by that using element by element multiplatinum, you have to set something of the same size as A into Ma
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Kamilu Sanusi el 27 de Ag. de 2022
Hello everyone. Please can someone explain the essense of creating empty matrix A, B, YG, & E in the following program:
% Winkel(zeit)=0-atan(arbeitspunkt.Vy(3)/arbeitspunkt.Vx(3))*180/pi;
PP(:,zeit)=arbeitspunkt.P;
QQ(:,zeit)=arbeitspunkt.Q;
UXT(zeit,:)=arbeitspunkt.Vx;
UYT(zeit,:)=arbeitspunkt.Vy;
IXT(zeit,:)=arbeitspunkt.Ix;
IYT(zeit,:)=arbeitspunkt.Iy;
A=[];
B=[];
YG=[];
E=[];
for i=1:size(DatGen,1)
[Gen, delta, Eq]=Generator(DatGen(i,:), arbeitspunkt);
% Matrix der Systemgelcihung von Generator i
% Ai(i)={Gen.Axy};
% Bi(i)={Gen.Bxy};
% YGi(i)={Gen.YGxy};
% Ei(i)={Gen.Exy};
% Matrix der Systemgelcihung von allen Generatoren
A=blkdiag(A, Gen.Axy);
B=blkdiag(B, Gen.Bxy);
YG=blkdiag(YG, Gen.YGxy);
E=blkdiag(E, Gen.Exy);
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Alisha el 23 de Sept. de 2022
Editada: Steven Lord el 23 de Sept. de 2022
It is not possible to create a blank array and then allow it to grow dynamically each time a user types a number into the command line. Instead, you ought to read the integers and add them to an Array. An ArrayList can grow dynamically and does not require an initial size.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Steven Lord el 23 de Sept. de 2022
It is possible to create an empty array and fill it by growing it dynamically. That's not a very efficient technique, though. Prefer to preallocate the array and fill it in so it doesn't have to grow with each new element you add to it.

Iniciar sesión para comentar.

### Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by