Want to delete ans from the output ou a function

2 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 19 Jan 2022
Edited: Stephen23 on 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 on 19 Jan 2022
Thank you so much! It's working perfectly now.

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!