Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Creating a function used loaded text files

1 vue (au cours des 30 derniers jours)
Amy
Amy le 14 Mar 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaire
dpb
dpb le 14 Mar 2014
Modifié(e) : dpb le 14 Mar 2014
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.

Réponses (1)

Image Analyst
Image Analyst le 15 Mar 2014
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

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by