フィルターのクリア

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 Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by