# Do one action to multiple arrays

2 visualizaciones (últimos 30 días)
Hao Lian el 19 de Sept. de 2017
Editada: Stephen23 el 19 de Sept. de 2017
For example if I want to delete the 2nd element for both a and b, a=[1 2 3]; b=[4 5 6]; a(2)=[]; b(2)=[]; I'm wondering is there a 1-step method to do this? Because I am dealing a large amounts of arrays. Thank you in advance!
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Stephen23 el 19 de Sept. de 2017
Editada: Stephen23 el 19 de Sept. de 2017
"Because I am dealing a large amounts of arrays"
That is the problem right there. Simply put all of the data into one array and your problem simply does not occur:
You see what I did there? By using better code design I just made your problem go away! So easy :)

Iniciar sesión para comentar.

KSSV el 19 de Sept. de 2017
a=[1 2 3]; b=[4 5 6];
A = [a;b]
A(:,2) = []
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Más respuestas (1)

José-Luis el 19 de Sept. de 2017
Editada: José-Luis el 19 de Sept. de 2017
The answer would be a slight adaptation of "don't use dynamic variable names" with the added issue of not being able to use a loop to generate variable names.
The short answer is: you're still going to need to specify which variables you need to delete an element from.
You can do that through a function that takes a variable number of arguments and deletes the second element in all of them. You'd still need to specify all the variables somehow.
In fact, whatever you do, you need to get the variable names. That could be through an introspective function like who and it's bound to be pretty ugly.
The sane way to do it is either put everything in an array if the dimensions are consistent or in a cell array if they are not. Then what you are asking becomes trivial.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Multidimensional Arrays 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