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