声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1051|回复: 1

[编程技巧] 我自己写的函数为什么是错的?

[复制链接]
发表于 2015-10-29 21:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  1. function [y,z]=yzfun(x)
  2. a = randn(2,1);
  3. if a(1)*a(2)>=0
  4.     y = a(1)*x;
  5. else
  6.     z = a(2)*x;
  7. end
复制代码
Error in yzfun (line 2)
a = randn(2,1);
Output argument "z" (and maybe others) not assigned during call to "E:\Matlab\yzfun.m>yzfun".

回复
分享到:

使用道具 举报

发表于 2015-10-30 18:50 | 显示全部楼层
输出变量数量不对,比如修改为
  1. function [y,z]=yzfun(x)
  2. a = randn(2,1);
  3. if a(1)*a(2)>=0
  4.     y = a(1)*x;
  5.     z = 0;
  6. else
  7.     y = 0;
  8.     z = a(2)*x;
  9. end
复制代码

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-18 08:36 , Processed in 0.053740 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表