Error when using (plotting) one m file data into another m file.
Mostrar comentarios más antiguos
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
Sindar
el 23 de Mzo. de 2020
What do the scripts A-D do? Are there any "clear" commands in them?
Adam Danz
el 23 de Mzo. de 2020
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
el 25 de Mzo. de 2020
Editada: shane watson
el 25 de Mzo. de 2020
Adam Danz
el 25 de Mzo. de 2020
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,

shane watson
el 28 de Mzo. de 2020
shane watson
el 1 de Abr. de 2020
Respuestas (1)
Adam Danz
el 1 de Abr. de 2020
0 votos
(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.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!