how i correct error in Matlab

4 Ansichten (letzte 30 Tage)
dalel amami
dalel amami am 10 Mär. 2021
Kommentiert: Jan am 11 Mär. 2021
I receice this error
Attempt to reference field of non-structure array
Error in perturb_method (line 136)
[j,k]=find(pop(i).mat.p==x)
  3 Kommentare
dalel amami
dalel amami am 11 Mär. 2021
not yet, i only rectify the syntax error, pop is a population of structred matix (mat) i want to knew the indices of a specific elemnet in the part p of matrix mat, how can i process please?
Jan
Jan am 11 Mär. 2021
I've explained already how to use the debugger to find out, what the cause of the error message is. If pop(i).mat is not a truct, you cannot access a not existing field p . Without seeing your code and the data, it is impossible to guess, what you want to do instead.
What does Matlab show you, when it stops at the error message in debug mode, for:
class(pop)
class(pop(i).mat)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 10 Mär. 2021
Bearbeitet: Jan am 10 Mär. 2021
The error message means, that either pop or pop(i).mat is not a struct, such that you cannot access a field using the dot.
Check this with the debugger. Type this in the command window:
dbstop if error
Then run your code again until it stops at the error. Now check the classes:
class(pop)
class(pop(i).mat)
But I'd expect another error message:
find(pop(i).mat.p=x)
% ^
Inside the FIND command, you should use the == operator for the elementwise comparison, not = for assining a value.

Weitere Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by