Borrar filtros
Borrar filtros

How can i use a struct/cell in a Function?

2 visualizaciones (últimos 30 días)
Timon Niedecken
Timon Niedecken el 15 de Mayo de 2018
Comentada: Timon Niedecken el 15 de Mayo de 2018
I have a given struct and want to combine the data within it to one array. Therefore i wrote this Function:
function vector = combinedata(Input)
n = length(Input.features);
j = 1;
for i = 1:n
nn = length(data.features{1,i}.geometry.coordinates);
for ii = 1:nn
vector(j,1) = data.features{1,i}.geometry.coordinates(ii,1);
vector(j,2) = data.features{1,i}.geometry.coordinates(ii,2);
j = j+1;
end
end
but when i try it, i get following error message:
pray = combinedata(data)
Undefined variable "data" or class "data.features".
Error in combinedata (line 5)
nn = length(data.features{1,i}.geometry.coordinates);
I have tried it outside the function and was able to use the length function without problems:
length(data.features{1,10}.geometry.coordinates)
ans =
4

Respuesta aceptada

James Tursa
James Tursa el 15 de Mayo de 2018
Editada: James Tursa el 15 de Mayo de 2018
The variable name you are using as the input argument in your function is "Input", not "data". There is no "data" variable in your function. Try changing all of your "data" names to "Input" inside your function.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by