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

1 次查看(过去 30 天)
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. *

采纳的回答

Walter Roberson
Walter Roberson 2018-6-27
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 个评论
Cynthia Dickerson
Cynthia Dickerson 2018-6-27
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by