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

7 views (last 30 days)
% 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
dpb
dpb on 15 Jul 2017
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...
Jared MacDonald
Jared MacDonald on 18 Aug 2017
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

Community Treasure Hunt

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

Start Hunting!