Borrar filtros
Borrar filtros

Can I assign NaN to output of iterative loops that are caught, and print which inputs are caught?

1 visualización (últimos 30 días)
I have a code that runs a series of iterative loops. I have the following code:
if true
for x=1:10
for i=1:z
try
B=50*i;
[BTRAIN,CNTER]=replica(TNSPEC,B);
[sds,sdskew,qrr] = qb(TNSPEC,BTRAIN,newspec,CNTER,radfrac,sensitiv);
bias=sds-expected_standard_deviation(j);
SDS_matrix((i),:)=[compass_points(j,:),B,sds,bias,sdskew];
catch
end
end
end
end
The last line, the SDS_matrix, gets averaged over six runs, and then assigned to a cell array. That 'catch' has been really important because it has caught a lot of inputs that generate errors in the function being called. My problem is, though, that I think that sds, sdskew, and qrr are staying assigned the last iteration's values before the next functional iteration occurs. Is there a good way to mark the inputs that raised errors, maybe fill in NaN values, so I can pull those rows out of my final matrix? Also, is there a way to generate an error log that tells me which error was raised by the inputs that got caught?
Thanks.
*Edit - to clarify, when I look at my final matrix, there are no holes in the data input to show that a value assignment was skipped, though I know some iterations have been caught. *

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Jun. de 2018
for x=1:10
for i=1:z
B=50*i;
sds = nan; bias = nan; sdskew = nan;
try
[BTRAIN,CNTER]=replica(TNSPEC,B);
[sds,sdskew,qrr] = qb(TNSPEC,BTRAIN,newspec,CNTER,radfrac,sensitiv);
bias = sds-expected_standard_deviation(j);
catch ME
end
SDS_matrix(i,:)=[compass_points(j,:),B,sds,bias,sdskew];
end
end
This will get as many of the values as could be computed with nan for the rest.
However, you are not using "x" inside your for loop, and you are always writing to the same row of the SDS_matrix. Also you are using j inside your loop but never change it, leaving us wondering if your j and x should be the same variable. If not, if j is set before the loop, then it is not clear why you would want to copy compass_points(j,:) as the first entry to all of the rows...
  1 comentario
Cynthia Dickerson
Cynthia Dickerson el 27 de Jun. de 2018
Thanks! The outer loop is actually more complicated; it determines some of the input variables for the called function. The whole code is a couple hundred lines. The snippet is actually repeated 5 times (a holdover from an old edit) rather than being assigned based off of the iteration count.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by