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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

James Tursa
James Tursa il 15 Mag 2018
Modificato: James Tursa il 15 Mag 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.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by