Reputation: 137
I want to create input dialog box in matlab. I am performing simple addition operation in MATLAB. Two variables name, a and b are needed to be given by user and then performing addition c=a+b; and display it in output. Both a and b should be positive integer only. I tried following:
a = inputdlg({'Enter positive integer (a)'});
b = inputdlg({'Enter positive integer (b)'});
c=a+b;
But it is giving following error:
Undefined function or method 'plus' for input arguments of type 'cell'.
Please suggest how can i code the above program in described way.
Upvotes: 1
Views: 949
Reputation: 13945
That's because the output of inputdlg
is a cell array containing a string; here a 1-cell array.
Hence you need to access the content of the cell array to perform the operation; for example using {curly brackets} : {a}
and {b}
.
In your case, since you are asking the use for a number, you need to convert the output, which is a string, to an actual number Matlab can use using for instance str2double
, which operates on cell arrays
c = str2double(a) + str2double(b)
Upvotes: 1