Want to delete ans from the output ou a function

조회 수: 2 (최근 30일)
Pedro Almeida
Pedro Almeida 2022년 1월 18일
편집: Stephen23 2022년 1월 19일
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
Stephen23
Stephen23 2022년 1월 19일
편집: Stephen23 2022년 1월 19일
" 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 2022년 1월 19일
Thank you so much! It's working perfectly now.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by