Error using num2cell Too many input arguments.

조회 수: 5 (최근 30일)
Alexandra Philip
Alexandra Philip 2020년 7월 8일
편집: Adam Danz 2020년 7월 13일
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
Alexandra Philip
Alexandra Philip 2020년 7월 8일
I am trying to use whatever the inputs in the Edit Fields are to be placed in the uitable. I tried to see if I need to convert to cell array as previously without the conversion I received this error:
Error using uitable Values within a cell array must be numeric, logical, or char
Rik
Rik 2020년 7월 8일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2020년 7월 8일
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
Alexandra Philip
Alexandra Philip 2020년 7월 8일
I was able to figure it out and correct the error.
Adam Danz
Adam Danz 2020년 7월 8일
편집: Adam Danz 2020년 7월 13일
"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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by