Error when using (plotting) one m file data into another m file.

Hello all,
Here I'm facing a problem, I have four files: file A.m, file B.m, file C.m, and file D.m. And one more file to plot data which is plot.m, now at very start I putted all other files(A,B,C,and D) in the plot.m. However, some varibles are not appearing in the figure and error "undefine varible" appear when plotting. While most of the varibles are in file C and D, the file C appears okay but file D doesnot, and mysteriously when I change name position of file C and file D then both shows error that is (C.m D.m plots appers for C.m only and problem appears in D.m) then if change position and write like this way (D.m and C.m) then error occurs. Point to note here C.m and D.m also use A.m and B.m in the startd. Please if you know the solution.

7 comentarios

What do the scripts A-D do? Are there any "clear" commands in them?
Are the m files all scripts (see scripts vs functions)? My guess is that one script depends on variables defined in another script and then the scripts are run out of order, you've got missing variables.
This is one reason my scripts are messy to work with.
The orange/red underlines and the orange right-side-tickmarks visible in the editor should show you warning/error messages and those messages should point to the problem.
shane watson
shane watson el 25 de Mzo. de 2020
Editada: shane watson el 25 de Mzo. de 2020
@Adam Danz, Thank you for your respose, Just to clearify @Sinder and you. m files are mixed like considering above example, A and B are script files, one is the class file (clearly including functions), C and D are flies that have varibles which I'm using in the plot file.
@Adam I agree with you that some of the varibles might be repeating and do you think that is the main problem? And I didn't clearly get your last point. Can you please explain?
There could be several problems and if the same variable name is used in multiple scripts that could definitely cause a problem. This is why it's recommended to avoid using scripts unless all of the code is contained within a single script (even then, a function is better, IMO).
" I didn't clearly get your last point."
When you view the code from the editor, you should see orange squiggly lines under sections that contain warning messages. You'll also see an organe tick mark in the right margine and the square at the top of the right side is orange. If the problem would cause an error, the colors would be red instead of orange.
Notice the variable a is assigned a value twice, below.
When you hover over the orange squiggle line,
When you hover over the orange tick on the right,
As usua thanks @Adam for satisftying answer :).
@ Adam I couldn't find option to accept your answer.
Adam Danz
Adam Danz el 1 de Abr. de 2020
Editada: Adam Danz el 21 de Jun. de 2020
Thanks, Shane. I copied my comment to the answers section. Comments can't be accepted.

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 1 de Abr. de 2020
(Comment copied to answers section).
There could be several problems and if the same variable name is used in multiple scripts that could definitely cause a problem. This is why it's recommended to avoid using scripts unless all of the code is contained within a single script (even then, a function is better, IMO).
" I didn't clearly get your last point."
When you view the code from the editor, you should see orange squiggly lines under sections that contain warning messages. You'll also see an organe tick mark in the right margine and the square at the top of the right side is orange. If the problem would cause an error, the colors would be red instead of orange.
Notice the variable a is assigned a value twice, below.
When you hover over the orange squiggle line,
When you hover over the orange tick on the right,

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Mzo. de 2020

Editada:

el 21 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by