Info

This question is closed. Reopen it to edit or answer.

Variables accessible in unrelated files?

2 views (last 30 days)
Amory Tillinghast-Raby
Amory Tillinghast-Raby on 5 Jan 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
Currently, on my computer, I have two Matlab files. One is saved to my desktop and one is saved to my documents folder. I see no reason why these two .m files should be able to access one another. Here is the code for the first .m file which is saved to my documents folder.
syms R
rstatic = .5;
comp = .5;
targetVolume = (4/3)*(pi)*(.5)^3;
startingCircumfrence = 2*pi*(.5);
%Preliminary Equations
d = rstatic + (R - comp);
a = (1/d)*((4*(d^2)*(R^2))-((d^2)-(rstatic^2)+(R^2))^2)^(1/2);
z = ((rstatic^2) - (((1/2)*a)^2))^(1/2);
capHeight1 = (rstatic - z);
capHeight2 = (comp - capHeight1);
capVol1 = ((pi*(capHeight1)^2)/3)*((3*rstatic)-capHeight1);
capVol2 = ((pi*(capHeight2)^2)/3)*((3*R)-capHeight2);
removedVolume = (capVol1 + capVol2);
%Volume Expansion
deformedVol = ((4/3)*(pi)*(R^3)) - removedVolume == targetVolume;
radiusFromExpansion = vpasolve(deformedVol,R,[.5 Inf]);
circumfrenceFromExpansion = (2*pi*radiusFromExpansion);
%Return the values
radiusFromExpansion %#ok<NOPTS>
circumfrenceFromExpansion %#ok<NOPTS>
Somehow, in the .m file that is saved to my desktop, I am able to call circumfrenceFromExpansion. The entirity of the desktop file is
circumfrenceFromExpansion
Can someone explain to me how this is possible and what I can do to prevent this? The two projects are unrelated and ideally I would like to reuse variable names.

Answers (0)

Community Treasure Hunt

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

Start Hunting!