passing strings to a function to call commands
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
I'd like to create a function to automate the passing variable names to statement. I tried to create a function to achieve it using is varargin and foo loop. The challenge is to pass unknown number for string names to a function call.
Manual method is as follow.
      Vdc(1,:) = logsout.get('Vdc').Values.Data(:,1) ;
      Vc(1,:) =logsout.get('Vc').Values.Data(:,1) ;
      I_L(1,:) =logsout.get('I_L').Values.Data(:,1) ;
The function I created with errors
function logger(varargin)
% input is in the format logger(Vdc,Vin,Iload)
% where "logsout" is the name of the object stored Vdc,Vin,Iload,IL,,,,
% I want to automatically extract selected variables and store them with 
% the original name
nsize=nargin;
 for k=1:size
 tag=spprintf(varagin(k));
 data(:,1) = logsout.get('Vdc').Values.Data(:,1) ;  % where tag='Vdc'
assignin('base',tag,data);
  end
Any suggestions appreciated.
댓글 수: 1
답변 (1개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!