output argument not assigned

조회 수: 3 (최근 30일)
aine gormley
aine gormley 2018년 10월 22일
댓글: aine gormley 2018년 10월 23일
Dear community,I have been continually hitting the following error in my code:
--
Output argument "var_ap" (and maybe others) not assigned during call to
"mf_field".
"Error in mf_srex (line 144)
[~, var_srex] = mf_field(var, mask);"
Below is the part of the code to which it is referring:
if length(size(var)) == 2
% get field mean
var_ap = nanmean(nanmean(var .* area )) ./ nanmean(nanmean(area ));
var_mp = nanmean(nanmean(var(mask) .* area(mask))) ./ nanmean(nanmean(area(mask)));
elseif length(size(var)) == 3
% get field mean for masked pixel
var_ap = NaN(size(var,3),1);
var_mp = NaN(size(var,3),1);
for j = 1:size(var,3)
vari = var(:,:,j);
var_ap(j,1) = nanmean(nanmean(vari .* area )) ./ nansum(nanmean(area ));
var_mp(j,1) = nanmean(nanmean(vari(mask) .* area(mask))) ./ nansum(nanmean(area(mask)));
end
end
Please can somebody offer some advice?
Thanks for your time.

채택된 답변

Image Analyst
Image Analyst 2018년 10월 23일
For some reason, you're never assigning anything to var_srex. To fix, just assign it to anything, such as 0 or null, as the very first line of mf_field :
var_srex = [];
Of course you may then get some error where var_srex is null and you expected something else, but you won't also get the error that var_srex is not assigned.
  댓글 수: 1
aine gormley
aine gormley 2018년 10월 23일
Thanks so much for your time

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Tursa
James Tursa 2018년 10월 22일
Based on what you have posted, it appears var has more than 3 dimensions, so you aren't getting into your code above.
  댓글 수: 1
aine gormley
aine gormley 2018년 10월 22일
Hi, thanks for your response. I just realised an error in the code I put above. All the ‘nanmean’ cases should be ‘nansum’. Does that make any difference?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by