From: Alan B on 5 May 2010 18:34 I have an idea for a debugging tool that would be very useful for me, I'm wondering if anyone has ever seen something like this: a program that determines the assignment dependencies of all variables in a given Matlab function. Ideally it would plot a graph of as well. The top of the plot would show all function inputs and hard-coded parameters, the bottom of the plot would show all function outputs. In between, linked nodes would be drawn such that any variable is linked to any variable whose value it depends on, and also to any variable whose value depends on it. I suppose a basic implementation via text scanning wouldn't be too difficult, but I don't want to reinvent the wheel if I don't have to. I can't seem to think of good search terms to look for this, has anyone seen anything like this on the FEX?
From: John D'Errico on 5 May 2010 20:25 "Alan B" <monguin61REM(a)OVETHIS.yahoo.com> wrote in message <hrsrou$e38$1(a)fred.mathworks.com>... > I have an idea for a debugging tool that would be very useful for me, I'm wondering if anyone has ever seen something like this: a program that determines the assignment dependencies of all variables in a given Matlab function. Ideally it would plot a graph of as well. The top of the plot would show all function inputs and hard-coded parameters, the bottom of the plot would show all function outputs. In between, linked nodes would be drawn such that any variable is linked to any variable whose value it depends on, and also to any variable whose value depends on it. > > I suppose a basic implementation via text scanning wouldn't be too difficult, but I don't want to reinvent the wheel if I don't have to. I can't seem to think of good search terms to look for this, has anyone seen anything like this on the FEX? It will be more difficult than you think to do this at all well. With nested functions, the tool would need to worry about what happens inside them. And of course eval or its cousins would cause massive headaches. Global variables too would drive you crazy. And suppose that you define a variable that overloads an existing matlab function? The tool would need to recognize the overloading. Yes, if you limit the possibilities, excluding anything inside an eval, globals, etc., you could do something simple. But the fact is, if the code is simple enough, you don't need such a tool anyway. John
From: Alan B on 6 May 2010 00:29 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hrt29h$d6c$1(a)fred.mathworks.com>... > It will be more difficult than you think to do this at > all well. With nested functions, the tool would need > to worry about what happens inside them. > > And of course eval or its cousins would cause massive > headaches. Global variables too would drive you crazy. > > And suppose that you define a variable that overloads > an existing matlab function? The tool would need to > recognize the overloading. > > Yes, if you limit the possibilities, excluding anything > inside an eval, globals, etc., you could do something > simple. But the fact is, if the code is simple enough, > you don't need such a tool anyway. > > John I know it isn't easy to do it *correctly*. Even before everything you listed, a few simple problems occurred to me - block comments, multi-line statements, and character strings that contain anything resembling Matlab code. I think, just the presence of these entities would necessitate half of a syntax parser, rather than simple line-by-line string matching. Globals, evals, loads, overloads, nested and subfunctions, all make it that much worse. However, M-Lint does provide a limited subset of this functionality - "the value assigned to X might never be used"; "input argument Y appears never to be used"; function return value Z appears to never be set". M-lint can't handle some of the cases you mentioned, but it is good for a quick hint once in a while. So, I know it has been partially implemented in a useful way. The code that I would like to use this for tends to be not much more sophisticated than a long (~300 lines) series of relatively simple (but dense) commands, saved as a script. Sometimes there are a few big if-else blocks or loops surrounding the bulk of the code. Sometimes the script starts with a load() and finishes with a save(). Basically, though, it does not tend to be too complicated in the sense that you warn against. I think you will tell me it is still a bad idea to become dependent on such a tool. You would be right. Can we still consider it, as a matter of curiosity? I wrote a very simple function that scans text for strings on LHS or RHS of assignment operators, and just spits out a list. I would like to see a function that is barely more sophisticated than this, say by making a first attempt at linking all of these scanned assignment statements. Thanks for the reply.
|
Pages: 1 Prev: Using Matlab GUIs within the HTML framework Next: uniform random variable |