Want to delete ans from the output ou a function

2 Ansichten (letzte 30 Tage)
Pedro Almeida
Pedro Almeida am 18 Jan. 2022
Bearbeitet: Stephen23 am 19 Jan. 2022
Whenever I use this function, it always spits back an ans in the command window, how do I prevent this from happening?
function [matriz, k, file] = carregar_dados (file)
file = input('Introduza o nome do ficheiro > ', 's');
fid = fopen(file);
if fid ~= -1
fprintf('O ficheiro foi aberto com sucesso! \n');
else
while fid == -1;
fprintf('O ficheiro não existe. \n');
file = input('Introduza o nome do ficheiro > ', 's');
fid = fopen(file);
end
end
k = 0;
matriz = [];
while ~feof(fid);
k = k + 1;
i = 0;
linha = fgetl(fid);
for i = 1:4;
linha(1) = [];
[valor, linha] = strtok(linha, ',)');
matriz(k,i) = str2num(valor);
end
end
fclose(fid);
end
  4 Kommentare
Stephen23
Stephen23 am 19 Jan. 2022
Bearbeitet: Stephen23 am 19 Jan. 2022
" I put a semicolon after calling the function..>"
No, you added a semi-colon in the function signature line. That will do nothing.
"and it still spits back an ans into the command window..."
Yes, because you did not put a semi-colon after the function when you call it.
"anything else I could try?"
You could put a semi-colon after the function when you call it.
But given that your function imports some data and then you assign this to ANS which you now want to ignore... I suspect that you should actually assign the function output to a variable in order to use that imported data for something.
Pedro Almeida
Pedro Almeida am 19 Jan. 2022
Thank you so much! It's working perfectly now.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by