Is it possible to have output in an input format?

Eg, if you type
>> var1
in the command line, that it would output:
var1 = [1, 2, 3, 4];
instead of
ans = ...
This could be usefull, to give output from one file to another by manually copy-pasting it ..
Thanks!

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Jan. 2012
dm = @(M) fprintf('%s = %s\n', inputname(1), mat2str(M));
Then
dm(var1)

Weitere Antworten (1)

Andrew Newell
Andrew Newell am 26 Jan. 2012

0 Stimmen

It would take a little programming. Your example could be done with
disp(['var1 = [',num2str(var1),']'])
but you'd need special cases to deal with other types such as strings.
Do you know about save?

Community Treasure Hunt

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

Start Hunting!

Translated by