How can I prevent cells becoming NAN cells after an event?

조회 수: 1 (최근 30일)
Alfonso Rodriguez
Alfonso Rodriguez 2016년 5월 10일
댓글: Alfonso Rodriguez 2016년 5월 10일
I am trying to work a simple arithmetic problem inside a cell array. I want to add all the rows from one column with all the rows from other column. I am doing this task with a push button with this code under it`s callback function:
function addCol_Callback(hObject, eventdata, handles)
data = str2double(get(handles.uitable1,'data'));
data(:,5) = data(:,3) + data(:,4);
set(handles.uitable1,'data',data);
I am able to get the arithmethic, but all the cells show the NaN message, even those where I had previously entered a number, or chosen a value from a choice list. Is there a way to get rid of the effects that the NaN cause in all the cells?
Here I present an Image before pressing the event button and an image after the button pressed.
%
  댓글 수: 1
Alfonso Rodriguez
Alfonso Rodriguez 2016년 5월 10일
편집: Alfonso Rodriguez 2016년 5월 10일
The mess is like this after pressing the button.
I just don´t want the NaN to show and mess my cells. I really just need to get the sum from the two columns and that`s it. I also need the choice list to stay the same as before the button was pressed. And also any other column to not be affected by the NaN.

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 10일
Why are you using
data = str2double(get(handles.uitable1,'data'));
The 'data' property should be a cell array, not all of which will be strings.
The choice arrays will be numeric indices into the cell array of strings entry in ColumnFormat entry for the column.
The entries for which the ColumnFormat is one of the numeric formats will be returned as numeric.
It is only the entries which are 'char' in ColumnFormat for which the column would be returned as string that need converting by str2double()
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 5월 10일
cell2mat() the columns that you need, and num2cell the result and write it into the data cell array.
Alfonso Rodriguez
Alfonso Rodriguez 2016년 5월 10일
Thanks Walter, This gives me a new insight.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by