Checking to see if a user has filled in a table in Matlab
Can this if (size(cost,1) == 2 && size(limit,1) == 2)
expression be used? Because I want to take the data from cost
table and limit
开发者_如何学编程table. The cost
table is 4 by 3 table and limit
table is 4 by 2 table. So i want to take the data (which are input from user) from limit
table. I have this code:
if P1 < limit(1,1)
P1 = limit(1,1);
lambdanew = P1*2*cost(1,3) + cost(1,2);
I can execute my program only if the user inserts the data into limit table but if the user did not insert the data, so it will be an error saying this:
Index exceeds matrix dimensions.
Error in ==> fyp_editor>Mybutton_Callback at 100
if P1 < limit(1,1)
So my question is how I can make if
statement for the limit table if the user did not enter the data?
Is it limit(0)
, limit = 0
or limit == 0
??
Can you initialize the limit table somehow so you know it exists but that the user didn't enter any information in it? If limit table is 4 by 2, try limit = zeros(4,2)
. Hope that helps.
If you want to make sure that limit
is an array of size (4,2), you can do the following
if ~all(size(limit)==[4 2]))
h = errordlg('please fill in all values for "limit"');
uiwait(h)
return
end
Thus, the user gets an error message popping up, after which the callback stops executing.
精彩评论