24小时热门版块排行榜    

查看: 809  |  回复: 1

cw277

木虫 (正式写手)

[求助] 一个matlab 返回值的问题~~

比如 我定义了一个Config.m文件   
function [X0 X1] = Config( round, X0,X1 )   % X0,X1 是一个长度为8的数组
  ....
end
% 现在我又想返回X0,X1这两个数组,但是这样子写在调用Config这个函数的时候根本没有成功返回这两个数组,不知道程序里面应该怎么实现?

我看了sort 函数却可以实现这样的功能,返回A数组
function [A,SortedIndex]= sort(A,SortBy,index)
%SORT sort CAGE project
%
% [A,SortedIndex]= sort(A,SortBy,index);
%    SortBy is {'eval','reverse', 'names' , 'types'}
%    index  sort part of project specified by indices

%  Copyright 2004 The MathWorks, Inc.
%  $Revision: 1.1.8.1 $  $Date: 2005/12/01 03:34:06 $

if nargin<2
    SortBy = 'eval';
end
if nargin>2
    A= subsref(A,substruct('()',{index}));
end

C= A.Connections;
index= 1:size(C,1);


switch lower(SortBy)
    case {'eval','reverse'}
        [notused,SortedIndex]= iSort(C,SortBy);
    case 'names'
        [notused,SortedIndex]= sort(A.Names);
    case 'types'
        [notused,SortedIndex]= sort(A.Type);
end
   
SortedIndex = index(SortedIndex);

A= subsref(A,substruct('()',{SortedIndex}));
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

感谢生活让我慢慢学会控制自己的情绪,学会包容与忍耐,学会不再去期待
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
jjdg: 金币+1, 感谢应助 2012-10-17 00:59:23
cw277: 金币+10, ★★★很有帮助, 谢谢~~ 2012-10-17 08:56:13
cw277: 金币+10, ★★★很有帮助 2012-10-18 10:34:05
写法没错,function [A,SortedIndex]= sort(A,SortBy,index)这样就是定义了2个返回值,要保证这2个变量都在函数体中被赋值,
调用的时候也必须用2个返回值形式的调用,例如 [a,b] = sort(A,SortBy,index);这样你就能得到2个返回值了
matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
2楼2012-10-16 23:02:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 cw277 的主题更新
信息提示
请填处理意见