How to send the value from test script(m file) to main m file which is not written as a function?

2 visualizaciones (últimos 30 días)
Hello all, I want to send the value of Modes{k} from other m file into example.m which is not written as a function. In other words, when I run the other m file(test script), example.m will directly start with the Modes{k} value, will not take an input from user.
example.m
Modes={'a';'b';'c'};
fprintf('Please select a mode\n')
fprintf('Modes:\n')
fprintf('[%d] "%s" \n',1,Modes{1})
fprintf('[%d] "%s" \n',2,Modes{2})
fprintf('[%d] "%s" \n',3,Modes{3})
.
.
k=input('Mode:','s');
[xt,ut,yout]=myfunc('model',model,'file',Modes{k},'manuel',true);
.
.
  4 comentarios
Yunus Ertugrul
Yunus Ertugrul el 14 de Sept. de 2018
Ok, I have two m files(testscript.m and example.m). I want to access a parameter which is an input from user in example.m using some codes in testscript.m. Is it clear?
Yunus Ertugrul
Yunus Ertugrul el 14 de Sept. de 2018
@StephanCobeldick I don't normally want to get rid of input commands because example.m needs those, I just need that in testing. for example we run testscript.m then we will perform a test in Modes{1} without any user input to example.m. Is this possible?

Iniciar sesión para comentar.

Respuestas (1)

Dimitris Kalogiros
Dimitris Kalogiros el 14 de Sept. de 2018
Write values of Modes into a file at your disk:
save('fileModes.mat','Modes')
then you can use
load fileModes.mat
everywhere you need it

Categorías

Más información sobre Testing Frameworks 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!

Translated by