Help with syntax for a self-made function

1 visualización (últimos 30 días)
Teshan Rezel
Teshan Rezel el 12 de Ag. de 2021
Comentada: Teshan Rezel el 16 de Ag. de 2021
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');
end
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".

Respuesta aceptada

Simon Chan
Simon Chan el 12 de Ag. de 2021
Editada: Simon Chan el 12 de Ag. de 2021
You have not define your output variable 'fields' in your function, so nothing returns from the function
  11 comentarios
Stephen23
Stephen23 el 14 de Ag. de 2021
Editada: Stephen23 el 14 de Ag. de 2021
"It seems like this technique doesn't allow for that."
Here are two simple approaches you could use. Either use the same index
for k = ..
RG(k) = regionprops(mask1, 'all');
RG(k).Area
..
end
or a temporary variable:
for k = ..
tmp = regionprops(mask1, 'all');
tmp.Area
..
RG(k) = tmp;
end
What did you try?
Teshan Rezel
Teshan Rezel el 16 de Ag. de 2021
@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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by