simple question: open another m file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sorry to ask. if I sub 2 variables(x,y) from the currently running first.m into second.m, and second.m will return 2 variables (a,b) back to first.m. I should write this in first.m:
[a,b]=second(x,y);
PS.the location of first.m and second.m is the same.
error message is: ??? Attempt to execute SCRIPT second as a function: C:\second.m
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 5 Mär. 2011
You can only use that syntax if the first line of the file second.m (that is not whitespace or all comments) starts with the keyword "function", such as
function [p,q] = second(m,n)
If second.m does not start with "function" then it is called a "script". Scripts cannot be passed parameters and cannot return values. Scripts do not have dummy parameter names like functions do. On the other hand, scripts have access to all of the variables of the function that starts them, and can read and write to those variables directly.
5 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!