简体   繁体   English

为什么会发生此错误:索引超出矩阵尺寸

[英]Why is this error happening: Index exceeds matrix dimensions

I am running a GUI system in MATLAB and I am a beginner with working with GUI's. 我正在MATLAB中运行GUI系统,并且是使用GUI的初学者。

The code is extensively long and so I am going to just put in what and where I have things and see if it is enough information for help to be given, thanks. 该代码很长,因此我将只放入我所拥有的东西和地方,看看是否有足够的信息可以提供帮助,谢谢。

in my first GUi I have this in the opening function: 在我的第一个GUI中,我在打开函数中有这个功能:

HW12_result_bhanford(handles.scan_age, handles.check_athlete, handles.radio_male, handles.radio_female)

this is supposed to be transferring these four variables over to my third GUI named HW12_result_bhanford 这应该是将这四个变量转移到名为HW12_result_bhanford的第三个GUI中

In my second GUI I have this written in the opening function: 在我的第二个GUI中,我在开始功能中写了这个:

age = varargin{1}
athlete = varargin{2}
male = varargin{3}
female = varargin{4}

I then use these four variables(age, athlete, male, female) later in the second GUI and I assume them to be the equivalent value of the corresponding variable passed from the first GUI. 然后,我稍后在第二个GUI中使用这四个变量(年龄,运动员,男性,女性),并假定它们是从第一个GUI传递的相应变量的等效值。 When I run everything the error that comes back is Index exceeds matrix dimensions. 当我运行所有内容时,返回的错误是索引超出矩阵尺寸。

if anyone could help me, that would be awesome. 如果有人可以帮助我,那将很棒。 If you cannot help without the entire code I understand. 如果您不能没有完整的代码,我就会理解。

You use varargin if your argument list is variable, and varargin has to be in your function definition. 如果参数列表是变量,则使用varargin ,而varargin必须在函数定义中。

function HW12_result_bhanford(varargin)

In this case function receive a cell array as an input, so you can get individual arguments with varargin{1} etc. 在这种情况下,函数接收一个单元格数组作为输入,因此您可以使用varargin{1}等获取单个参数。

If you put your arguments together as a structure, you can pass this structure as an argument along. 如果将参数作为结构放在一起,则可以将此结构作为参数传递。

function HW12_result_bhanford(handles)

But if the function definition has individual arguments, for example, 但是,例如,如果函数定义具有单独的参数,

function HW12_result_bhanford(age, athlete, male, female)

you cannot use varargin , just process the arguments as is. 您不能使用varargin ,仅按varargin处理参数。

Read more on how to use VARARGIN . 阅读更多有关如何使用VARARGIN的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM