Why does Matlab not recognize fieldnames function?

1 回表示 (過去 30 日間)
Volker
Volker 2024 年 5 月 20 日
コメント済み: Volker 2024 年 5 月 20 日
Hi,
Back in the past I used the 'fieldnames' function to retrieve fieldnames. But suddenly it´s not working anymore.
Strangely the function works before starting my script as console input. But as soon as I start my script, the function doesn´t get recognized anymore. It also works in other scripts. See code below.
Thank you in advance!
if length(other_data.digitalMap) == 1 || length(results.digitalMap) == 1
fieldnames = fieldnames(results.digitalMap);
for y =1: length(other_data.digitalMap)
for z = 1:length(fieldnames)-1
field_name = fieldnames{z};
results.digitalMap(y).(field_name) = other_data.digitalMap(y).(field_name);
end
end
end
%Strangely the function works before starting my script as console input:
% Create a structure with some fields
myStruct.name = 'John';
myStruct.age = 30;
myStruct.occupation = 'Engineer';
% Get the field names of the structure
fields = fieldnames(myStruct);

採用された回答

Torsten
Torsten 2024 年 5 月 20 日
移動済み: Torsten 2024 年 5 月 20 日
You overwrite the "fieldnames" function by setting it to a variable value:
fieldnames = fieldnames(results.digitalMap);
  1 件のコメント
Volker
Volker 2024 年 5 月 20 日
Thank you! Little detail, but this was the solution!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by