필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Creating a function used loaded text files

조회 수: 1 (최근 30일)
Amy
Amy 2014년 3월 14일
마감: MATLAB Answer Bot 2021년 8월 20일
I have the following code:
function x = rZ(delta, aSqr)
load(delta);
load(aSqr);
x = delta./aSqr;
end
Where delta and aSqr are .txt files I have loaded in containing double workspace variables. When the function is ran in the command window the following error is thrown up:
Error using rZSum (line 2)
Not enough input arguments.
Would anyone be able to advise me on where Im going wrong? Thank you in advanced.
  댓글 수: 1
dpb
dpb 2014년 3월 14일
편집: dpb 2014년 3월 14일
The error refers to a function rZSum which is nowhere to be seen...
Need the error in context of the actual session that generated it.
Also, as written function rZ arguments delta and aSqr would have to be existing filenames (which I guess maybe is what your description means, not already loaded?) If you've already loaded them, then you don't need the load again.

답변 (1개)

Image Analyst
Image Analyst 2014년 3월 15일
Try something like (untested)
% Inputs: two strings that are filenames.
function x = rZ(delta, aSqr)
try
x = []; % Initialize.
s1 = load(delta); % Load variables in the delta file into the s1 structure.
s2 = load(aSqr); % Load variables in the aSqr file into the s2 structure.
% Now assume that there is a variable called delta in the delta mat file.
% and a variable called aSqr in the aSqr mat file.
% Divide them element by element.
if size(s1.delta) == size(s2.aSqr)
x = s1.delta ./ s2.aSqr;
else
errorMessage = sprintf('Error size of delta does not match size of aSqr.\Cannot divide them')
uiwait(warndlg(errorMessage));
end
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by