Info
此问题已关闭。 请重新打开它进行编辑或回答。
Creating a function used loaded text files
1 次查看(过去 30 天)
显示 更早的评论
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
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
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
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!