抑制功能输出 [英] Suppress function output

查看:80
本文介绍了抑制功能输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的函数,它使用textscan将数据读入变量.

I have a short function which uses textscan to read data into a variable.

我的问题是我总是这样:

My problem is that I always get this:

>>function('function.txt')

    ans = 

        {10x1 cell}    {10x1 cell}    {10x1 cell}    [10x1 double]

除了在用来调用该函数的行的末尾添加半冒号外,还有什么方法可以抑制这种情况?我希望能够在不添加分号的情况下将其抑制.运行此功能时,我根本不显示任何内容,我只想加载文件.

Is there any way to suppress this, apart from adding a semi colon to the end of the line I use to call the function? I'd like to be able to suppress it without adding the semi colon. I don't want to display anything at all when running this function, I just want to load my file.

推荐答案

您可以通过删除函数的输出参数(或返回值)来抑制输出. 或者 尝试使用Variable Number of Outputs,请参见支持变量输出数量

You can suppress the output by remove output arguments (or return values) of the function. OR Try use Variable Number of Outputs, see Support Variable Number of Outputs

function varargout = foo
    nOutputs = nargout;
    varargout = cell(1,nOutputs);
    for k = 1:nOutputs;
        varargout{k} = k;
    end
end

您键入>>foo却一无所获. 您键入>>a=foo并得到>>a=1. 您键入>>[a,b]=foo并得到>>a=1 >>b=2.

You type >>foo and get nothing. You type >>a=foo and get >>a=1. You type >>[a,b]=foo and get >>a=1 >>b=2.

因此,您可以通过不提供任何输出参数来抑制输出.

You can thus suppress output by NOT providing any output arguments.

这篇关于抑制功能输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆