MATLAB Answers

Error using num2cell Too many input arguments.

14 views (last 30 days)
Alexandra Philip
Alexandra Philip on 8 Jul 2020
Edited: Adam Danz on 13 Jul 2020
I am using the app designer and one of the callbacks, I receive an error in the code:
Error using num2cell
Too many input arguments.
for this line of code:
data=num2cell(app.AccelSNEditField,app.degEditField,...
app.degEditField_2,app.degEditField_3,app.degEditField_4,app.EditField,app.EditField_2,...
app.EditField_3,app.EditField_4);
I am intending to use the code to display within uitable with the data inputted by the user using the Edit fields. I first used:
value = app.TestDateDatePicker.Value;
Testdate = cellstr(datestr(value));
Then used the following code to create the uitable figure:
ATdata=[Testdate data];
ATdata=uitable(uifigure,'ColumnName',{'Accel S/N'; 'Test date' ;'Accel_0' ;'Accel_90'; 'Accel_180'; 'Accel_270';...
'Temp_0' ;'Temp_90'; 'Temp_180' ;'Temp_270'},'Data',ATdata);
Any suggestions to correct the error?
  3 Comments
Rik
Rik on 8 Jul 2020
I don't understand either your goal or your process. Please try breaking it down into smaller steps: what data do you have, and where do you want to put it?

Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 8 Jul 2020
I'm guessing that the edit field all contain either scalar numeric values or row vectors of numeric values. If that's the case, and if you're horizontally concatenating those values, you just need to enclose the values in square brackets [ ].
data=num2cell([...
app.AccelSNEditField,...
app.degEditField,...
app.degEditField_2,...
app.degEditField_3,...
app.degEditField_4,...
app.EditField,...
app.EditField_2,...
app.EditField_3,...
app.EditField_4, ...
]);
This should result in a 1xn cell array of scalar numeric values.
It's not clear what you want to do with those values.
If you have an existing UI table named ATdata and you want to vertically concatenate the data values with the existing values in the table, and if the number of columns in the table matches the number of columns in data,
ATdata.data = [ATdata.data; data];
If you're trying to horizontally concatenate the values,
ATdata.data = [ATdata.data, data];
  6 Comments
Adam Danz
Adam Danz on 8 Jul 2020
"The Edit Fields are determined by whatever the user inputs, so they may vary with different users."
So, there's no restrictions whatsoever? Any of the following inputs would be accepted?
  • 10
  • 1 2 3
  • abc def
  • p98q4ur;adkfj
  • (empty)
  • 10:20
  • "10:20"
If so, that's poor design. You should include feedback in your code that tells the user what types of values are acceped and then clears unacceptable values.
If you do want a table of mixed values, the table needs to be a cell array.
I still have no idea what the table and the inputs should be. I can't provide additional suggestions without some examples.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!