Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Remove a range of cells from a cell array using pushbutton

조회 수: 1 (최근 30일)
Matt
Matt 2017년 7월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
I have two cell arrays; one visible in a uitable in the GUI (current_data) and the other is generated by the user selecting the 'message/word' that they would like to remove in a drop down menu (data2remove) and selecting the remove button. How do I remove this data, selected by the user, from the cell array displayed in the GUI? I have tried the below:
current_data(data2remove) = [];
However, it gives me the following error: Function 'subsindex' is not defined for values of class 'cell'. Any help would be greatly appreciated.

답변 (1개)

Jan
Jan 2017년 7월 13일
편집: Jan 2017년 7월 13일
Posting some explicite values for the arrays would be useful. But let me guess:
current_data = setdiff(current_data, data2remove);
This removes all strings from current_data, which appear in data2remove.
Please note:
current_data(data2remove) = [];
If data2remove is a cell string, this trial is based on pure guessing. This kind of "shotgun programming" is not useful, but near to produce random results. But it is a good idea to post in the forum, what you have tried so far. Even if the code fails, it can be a useful hint of what you want to achieve.
  댓글 수: 2
Matt
Matt 2017년 7월 13일
Hi Jan,
I have tried what you suggested but it doesn't like it. I think this is because my cell array doesn't contain solely strings. This is a picture of the controls that I have (obviously the table is not pictured). The code below removes the strings from the listbox fine, it just doesn't remove the data from the cell array.
RemovedData = getappdata(handles.wordSel_menu, 'Data');
selected = get(handles.activeDataBox,'Value');
prev_str = get(handles.activeDataBox, 'String');
current_data = get(handles.data_table, 'Data');
if ~isempty(prev_str)
current_data(RemovedData)= []; % I tried this one first
current_data = setdiff(current_data, RemovedData); % Then tried your suggestion.
set(handles.data_table, 'Data', current_data);
prev_str(get(handles.activeDataBox,'Value')) = [];
set(handles.activeDataBox, 'String', prev_str, ...
'Value', min(selected,length(prev_str)));
end
Jan
Jan 2017년 7월 13일
@Matt: "it doesn't like it" is not useful to explain, what you observe. Please post a copy of the complete error message instead.
The shown code does not explain, what the variables contain. The screenshot does not have any relation to the problem also. Introducing the new name "RemovedData" increases the confusion level. Please concentrate on the actual details required to solve the problem:
  1. What is the contents of "current_data" and "data2remove"?
  2. What should be removed from what?
  3. Which error message do you get with the suggested solution?

이 질문은 마감되었습니다.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by