Help with syntax for a self-made function

조회 수: 2(최근 30일)
Teshan Rezel
Teshan Rezel 2021년 8월 12일
댓글: Teshan Rezel 2021년 8월 16일
Hi folks,
I have the following function defined in Matlab but am getting an error when running. The error and the code are below. May I please ask for help with debugging this?
Thanks in advance
function fields = populateFields(index, structure)
Area(index) = getfield(structure, 'Area');
MajorAxisLength(index) = getfield(structure, 'MajorAxisLength');
MinoeAxisLength(index) = getfield(structure, 'MinorAxisLength');
Eccentricity(index) = getfield(structure, 'Eccentricity');
Orientation(index) = getfield(structure, 'Orientation');
ConvexArea(index) = getfield(structure, 'ConvexArea');
Circularity(index) = getfield(structure, 'Circularity');
EquivDiameter(index) = getfield(structure, 'EquivDiameter');
Solidity(index) = getfield(structure, 'Solidity');
Extent(index) = getfield(structure, 'Extent');
Perimeter(index) = getfield(structure, 'Perimeter');
MaxFeretDiameter(index) = getfield(structure, 'MaxFeretDiameter');
MaxFeretAngle(index) = getfield(structure, 'MaxFeretAngle');
MinFeretDiameter(index) = getfield(structure, 'MinFeretDiameter');
MinFeretAngle(index) = getfield(structure, 'MinFeretAngle');
function call:
[matrix, numObjects] = bwlabel(mask1);
rg = regionprops(matrix, 'all');
fields = populateFields(1, rg);
The error:
Output argument "fields" (and maybe others) not assigned during call to "Threshold>populateFields".

채택된 답변

Simon Chan
Simon Chan 2021년 8월 12일
편집: Simon Chan 2021년 8월 12일
You have not define your output variable 'fields' in your function, so nothing returns from the function
  댓글 수: 11
Teshan Rezel
Teshan Rezel 2021년 8월 16일
@Stephen Cobeldick thanks for this! I tried the former, but run across this error when partway through the loop, and am not sure what's causing it...I tried defining the variable RG = zeros(numImages, 32) at the start but the error still occurs at the 465th value of i. Can I please ask you why this might be?
Unable to perform assignment because the left and right sides have a different number of elements.

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

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by