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

2 Ansichten (letzte 30 Tage)
shane watson
shane watson am 22 Mär. 2020
Bearbeitet: Adam Danz am 21 Jun. 2020
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 Kommentare
shane watson
shane watson am 1 Apr. 2020
@ Adam I couldn't find option to accept your answer.
Adam Danz
Adam Danz am 1 Apr. 2020
Bearbeitet: Adam Danz am 21 Jun. 2020
Thanks, Shane. I copied my comment to the answers section. Comments can't be accepted.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam Danz
Adam Danz am 1 Apr. 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,

Kategorien

Mehr zu Function Creation 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