Can I assign NaN to output of iterative loops that are caught, and print which inputs are caught?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Cynthia Dickerson
il 27 Giu 2018
Commentato: Cynthia Dickerson
il 27 Giu 2018
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. *
0 Commenti
Risposta accettata
Walter Roberson
il 27 Giu 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...
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!