필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Timon Niedecken
Timon Niedecken 2018년 5월 15일
댓글: Timon Niedecken 2018년 5월 15일
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.
  댓글 수: 1
Timon Niedecken
Timon Niedecken 2018년 5월 15일
oh man, how could i be so stupid :D thx alot!

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

추가 답변 (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