What is the "visibility" of a variable between scripts, particularly in a Live script?

% portion of first section in live script
grid1 = [546500, 8210000; 576500, 8230000];
% portion of second section in live script referring to separate function 'setupMainGrid'
BathyGrid1 = setupMainGrid(ADMdata, GEBdata, grid1);
Error message: Undefined function 'grid1' for input arguments of type 'double'.

6 Comments

Not enough context to tell what's going on. Scripts are run in the command workspace in which all variables are created and so are available.
However, I don't know what you mean by "live script"???
The Live Editor (link) that produces Live Scripts (link) was introduced recently. (The documentation doesn’t mention the release, and I’ve forgotten it.) It produces the same ‘.m’ files the ‘regular’ editor produces.
The advantage is that it allows LaTeX formatting, and execution of the files without having to leave the editor. (I don’t have much experience with it because I’m a creature-of-habit who still uses the ‘regular’ editor for essentially everything, so I rarely use it.)
Hmmm....wonder does it create its own context then, maybe, for each file so perhaps there is a scope problem here??? (That wouldn't exist to run scripts sequentially from command line as we old fogies do)
I'm so set in my habits I don't even use the builtin editor unless need to use debugger; it can't remap keys to the Brief editor and I'm too stubborn to learn anything new... :)
There's a note "MATLAB supports live scripts in versions R2016a and above. You can open live scripts as code only files in MATLAB versions R2014b, R2015a, and R2015b" at the link under the above top level.
The introduction that says "_A MATLAB® live script is an interactive document that combines MATLAB code with embedded output, formatted text, equations, and images in a single environment called the Live Editor._" makes me think it's not at all unlikely that one live script doesn't have access to another's environment although it doesn't say so explicitly.
I’ve used the built-in Editor since it first appeared. When I first started with MATLAB, ‘notepad’ was the only option, and it was like typing on punchcards — no formatting or anything else. I like the formatting and other options in the Editor.
I don’t know enough about the Live Editor to comment. We may have to wait for someone at TMW to notice this thread and weigh in with the details.
I added ‘live editor’ and ‘live script’ to the ‘Tags’.
Brief has language templates for all that plus many other niceties for programming that the Matlab editor lacks--the column selection facility one that I miss as much as many. The language templates are extensible as they're written in a simplified C syntax and compiled by a companion compiler so over 30+ yr I've modified them quite a bit...it's just too comfortable an environment to give up.
The only disadvantage is as say the builtin debugger and the code analyzer; if I were building production code I'd use it occasionally to evaluate its style hints for inclusion or not.
Don't know why the TMW-supplied editor can't have the other amenities production coding editors have had for many years; I suppose that MS supplies such a braindead one with VS is the problem any more; people think its ok just because it has market share by dint of MS being the bully in the room...
As far as OP's query, yeah, I can't even create one to test the hypothesis so it'll take somebody who can to try it out...
Well, actually, Star, it shouldn't take but a line or two to try it, it would seem. If you make one that defines an array and a second that tries to use that array, can the second "see" the first?
Then if you use global does it make any difference it not? I'd guess "no" and "no" are the results based on OPs question but I may have misinterpreted, too...
Hi Isak,
Live scripts have the same variable visibility as traditional scripts. That is, variables you create in a live script appear in the base workspace. So, I didn't run your exact example, but "grid1" should be visible to the next section of your live script, or another script, for that matter.
When you ran your first section, did you see "grid1" in the workspace browser?
Thanks, Jared
MathWorks

Sign in to comment.

Answers (0)

Categories

Find more on Live Scripts and Functions in Help Center and File Exchange

Asked:

on 15 Jul 2017

Commented:

on 18 Aug 2017

Community Treasure Hunt

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

Start Hunting!