Delete particular structure arrays

2 visualizaciones (últimos 30 días)
Fernando
Fernando el 29 de Mayo de 2012
Hi,
I'm generating some data in a random way, creating different structure arrays. Consider the following example with 3 different cases. Each case has 4 different variables. For each case (i:1:3) I have mk(i).n that has the number of observation in case i (n is randomly generated for each i, and as n represents the number of observations, each case has a different number of observations), mk(i).x which has "characteristics" also randomly generated (and a function of mk(i).n), mk(i).z and mk(i).u, both also randomly generated (and also a function of mk(i).n). Then I generate a random vector of parameters (say p0). Finally, given the random parameters, for each mk(i) I have a function, called FOC.m, that computes, for a given parameter a, the value of the left hand side of an equation of the form a*f(x,n,z,u,p0)=0. This is, given the random data already generated and "a", I compute the left hand side of the previous equation. I use fsolve to search for the "a" that solves this system, for each i. This "a" is in fact an "a(i)" in the sense that each mk(i) has its own "a(i)" that is supposed to solve that system for that particular mk(i).
However, as the data is randomly generated without much structure, it might be that for a certain mk(i) there is no solution (or that fsolves fails to find a solution), in which case I'm left with a(i)=a0 (a0 is the initial value for a). Given this, I would like to drop those mk(i)'s that resulted in no solution, and I have no idea how to actually do this. After doing so, I would also like to "rename" the remaining mk's in such a way that they are "one after the other". By this I mean that, assuming that in my example with three mk's the second one resulted in no solution, then I want to delete mk(2) with all the data that it has "inside" and then I want to rename the remaining ones so that now I just have mk(1) and mk(2) and that the n, x, z and u are also "relabeled". Of course, in practice I have a lot of mk's, so I can't do it by hand. I need to be able to identify the ones that received a(i)*==a0(i) and delete them with all the information they have. Any ideas would be really appreciated.
Thanks,
Fernando

Respuestas (1)

Walter Roberson
Walter Roberson el 29 de Mayo de 2012
For the deleting part, mk(k) = []
  1 comentario
Fernando
Fernando el 30 de Mayo de 2012
Thanks, but that doesn't seem to be working. For example, I know that for i=7 the system has no solution. If I just do mk(7)=[], nothing is erased, and all information related to mk(7) remains.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by