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

2 次查看(过去 30 天)
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

采纳的回答

James Tursa
James Tursa 2018-5-15
编辑:James Tursa 2018-5-15
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by