Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Creating a function used loaded text files

1 visualización (últimos 30 días)
Amy
Amy el 14 de Mzo. de 2014
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentario
dpb
dpb el 14 de Mzo. de 2014
Editada: dpb el 14 de Mzo. de 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.

Respuestas (1)

Image Analyst
Image Analyst el 15 de Mzo. de 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

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by