필터 지우기
필터 지우기

How can I run publish() in a workspace other than base?

조회 수: 2 (최근 30일)
Tom Clark
Tom Clark 2015년 12월 4일
댓글: Tom Clark 2015년 12월 4일
I'm using the publish() function to build up an automated reporting process. BUT, whenever I call publish() from within a function, it attempts to execute its target in the MATLAB base workspace, not the workspace of the present function. The following code generates an error:
function callingFunction()
a = 10;
publish(myReportingScript)
where myReportingScript.m contains:
disp(a)
If there is no variable a in MATLAB's base workspace, this simply doesn't work. Surely publish() should be executing in the workspace of its caller, not always the base workspace??? How can I get around this?
[Note: I also tried converting my script to a function and calling with:
function callingFunction()
a = 10;
options.codeToEvaluate = 'myReportingFcn(a)'
publish(myReportingFcn)
... but that doesn't work either.
  댓글 수: 1
Tom Clark
Tom Clark 2015년 12월 4일
Not a full answer, but I developed a workaround which adds the requisite variables to the base workspace then deletes them after publishing.
Requires:
- putvar(), on the FEX, from John d'Ericco (John saves me yet again!)
- care that this doesn't overwrite then delete similarly named variables in that workspace.
options.codeToEvaluate = 'myReportingFcn(a)';
putvar(a)
publish('trainFoilReport.m',options)
evalin('base','clearvars a')

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by