필터 지우기
필터 지우기

Unrecognized Field name in struct error, even though same Fieldname clearly in struct

조회 수: 98 (최근 30일)
I am writing a GUI, that automatically imports data from a table and sorts it into a struct with fields. I created a cell with strings "VN" (VariableNames), with data_in beeing a 401x6 table in this example.
app.VN = app.data_in.Properties.VariableNames;
% Manually outputting VN into workspace shows:
VN=app.VN
VN =
1×6 cell array
Columns 1 through 5
{'x1_1_1RadVorneR…'} {'x1_1_1RadVorneR…'} {'x2_1_1Sitzschiene'} {'x2_1_1Sitzschie…'} {'x3_1_1Sitzkissen'}
Column 6
{'x3_1_1Sitzkisse…'}
so i can later open each field in my struct "data" by calling it like this for example:
app.data.(app.VN{i})
My Problem: I want to compare different Fields with eachother in an if statement, with "i" beeing used from a for function:
for i=2:width(app.data_in)
if app.data.(app.VN{1}) == app.data.(app.VN{i})
%...
But i get the warning message "Unrecognized field name "x1_1_1RadVorneRechts"." in the line of the if statement.
If I manually output the struct "data" into the workspace, one line before the aforementioned "for" function starts, i get this output, clearly showing, that the field name exists:
data=app.data
data =
struct with fields:
x1_1_1RadVorneRechts: [401×1 double]
x1_1_1RadVorneRechts_2: [401×1 double]
x2_1_1Sitzschiene: [401×1 double]
x2_1_1Sitzschiene_2: [401×1 double]
x3_1_1Sitzkissen: [401×1 double]
x3_1_1Sitzkissen_2: [401×1 double]
Why do i get this error message and how do i resolve it? It is critical for the rest of the GUI, that i can compare different field values with eachother.
  댓글 수: 9
Janik Ruge
Janik Ruge 2021년 8월 21일
Did that, i just paste the entire workspace result here:
datafields =
6×1 cell array
{'x1_1_1RadVorneRechts' }
{'x1_1_1RadVorneRechts_2'}
{'x2_1_1Sitzschiene' }
{'x2_1_1Sitzschiene_2' }
{'x3_1_1Sitzkissen' }
{'x3_1_1Sitzkissen_2' }
All VN data fields found
% Rest was in red letters, as per usual for an error msg
Unrecognized field name "x1_1_1RadVorneRechts".
Error in SS14/DateiAuswahl2 (line 355)
if app.data.(app.VN{1}) == app.data.(app.VN{i})
Error in SS14/import2 (line 288)
app.DateiAuswahl2;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 410)
Error while evaluating Button PrivateButtonPushedFcn.
Janik Ruge
Janik Ruge 2021년 8월 21일
편집: Janik Ruge 2021년 8월 21일
I found my mistake. Later during the if queue i rename the field with renameStructField by mistake. Before, i had that command after the for queue and when restructuring some code i misplaced it. I made the mistake of not searching the failure later during the "for" queue.
This caused the program to rename the field, but not update VN, thus when continuing the "for" queue, the first field of "data" was renamed, while VN wasn't. I now update VN after renaming the Field during the for queue, which fixed the problem.
Thanks for the help anyways! Would not have found it without that precise help.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by