输出参数过多 [英] Too many output arguments

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

问题描述

我不是MATLAB中的核心程序员,我从youtube和书籍中学到了所有东西.这可能是一个非常简单的问题,但我不知道该搜索什么.

I am not a very hardcore coder in MATLAB, i have learned every thing from youtube and books. This might be a very simple question but i do not know what search for answer.

在MATLAB中,我正在尝试做类似的事情.

In MATLAB i am trying to do something like this.

>>[a,b,c] = [1,2,3]

我想要这样的输出.

>> a = 1 
b = 2
c = 3

因此,基本上的问题是:-用户将在代码启动时定义变量矩阵([a,b,c]),并且在代码处理过程中,将显示类似的矩阵,并且将询问输入矩阵( [1,2,3]).我不知道如何在不编写循环代码的情况下做到这一点,在循环代码中,我将从变量矩阵中提取每个变量,然后通过eval函数将值保存在该变量中.

So Bsically question is that : - User will define the matrix of variables([a,b,c]) in staring of code and during process of the code similar matrix will be displayed and as input a matrix will be asked([1,2,3]). I dont know how do this without writing a loop code in which i will take every single variable from variable matrix and save the value in that variable by eval function.

以上编写的代码是错误的,我知道,我可以使用"for"循环和"eval"功能来做到这一点.

well above written code is wrong and i know, i can do this with "for" loop and "eval" function.

但是问题是没有.变量(a,b,c)永远不会是常数,我想知道MATLAB中是否有内置函数或方法比for循环更好地工作.

but problem is that no. of variables(a,b,c) will never be constant and i want know if there exist any in built function or method in MATLAB which will work better than a for loop.

正如我之前所说,我不知道该怎么搜索这个问题,或者这是一个非常普遍的问题. 无论哪种方式,如果您至少可以告诉我要搜索什么或将我重定向到相关问题,我都会很高兴.

As i told earlier i don't know what to search for such a problem and either this is a very common question. Either way i will be happy if you can at least tell me what to search or redirect me to a related question.

如果您需要更多信息或需要任何更正,请务必写信.

Please do write if you want any more information or for any correction.

谢谢.

推荐答案

deal函数可以针对固定数量的输入执行此操作:

The deal function can do this for a fixed number of inputs:

[A,B,C]=deal(1,2,3)

如果您不知道将事先获得多少输入,则必须做一些鬼混.这是我想出的:

If you don't know how many inputs you will get beforehand, you have to do some fooling around. This is what I've come up with:

V=[1,2,3,4,5,6,7]
if length(V)>1
    for i=1:length(V)
        S{i}=['A' num2str(i)];
        G{i}=['V(' num2str(i) ')'];
    end
    T=[S{1} ','];
    R=[G{1} ','];
    for i=2:length(V)-1
        T=[T S{i} ','];
        R=[R G{i} ','];
    end
    T=[T S{length(V)}];
    R=[R G{length(V)}];
    eval(['[' T ']=deal(' R ')'])
else
    A1=V
end

但是当您不知道会有多少痛苦时,再处理A1,...,An会很痛苦!

But then dealing with A1, ... , An when you don't know how many there are will be a pain!

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

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