how to take .m files vector values to another .m file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohamuud hassan
el 13 de Mayo de 2015
Respondida: Jan
el 13 de Mayo de 2015
hello all. i have two script files and i want to take first script outputs to reuse again for the second script file. so, how i can share first x.m vector values to the another y.m .
0 comentarios
Respuesta aceptada
Jan
el 13 de Mayo de 2015
It is the nature of scripts that this happens in every case. The variables created in the first script are written to the workspace (the currently active "container" for variables) and another script, which is called later can access them directly.
% script file 1: scripta.m
v = 2:17;
% script file 2: scriptb.m
disp(v * 2);
Now you can call the scripts from the command line, another script or from a function:
scripta;
scriptb;
Because the workspace is polluted by variables as soon as the scripts get more powerful, functions are smarter:
% function file 1: funca.m
function v = funca
v = 2:17;
% function file 2: funcb.m
function funcb(v)
disp(v * 2);
Now this is called from the command line, a script or from inside another function by:
v = funca;
funcb(v);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!