cell1={'a'}
cell2={[],'b'}
cell3={[],[],'c'}
cell4={[],[],[],'d'}
cell5={[],[],[],[],'e'}
how can i combine all these cells data.?
Desires result
cell={'a','b','c','d','e'}

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2015 年 5 月 20 日
編集済み: Andrei Bobrov 2015 年 5 月 20 日

0 投票

out1 = [cell1,cell2,cell3,cell4,cell5];
cell0 = cellstr(cat(1,out1{:}))'

1 件のコメント

Nouman Ashraf
Nouman Ashraf 2015 年 5 月 20 日
編集済み: Andrei Bobrov 2015 年 5 月 20 日
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global i
i=1
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global i
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Enter your name'};
dlg_title = 'Name';
num_lines = 1;
def = {'','hsv'};
answer(i)=inputdlg(prompt,dlg_title,num_lines,def)
i=i+1
i am executing this above code. evert time user press push button 2 enter his name and store its name into answer. but instead of updating the answer it empties the previous names and just store the last name. how can i store every name into answer when user press push button 2 and enter his name. push button 1 is just to initialize i

サインインしてコメントする。

Walter Roberson
Walter Roberson 2015 年 5 月 20 日

0 投票

cell0 = {cell1{:},cell2{:},cell3{:},cell4{:},cell5{:}};
cell0(cellfun(@isempty,cell0)) = [];

5 件のコメント

Andrei Bobrov
Andrei Bobrov 2015 年 5 月 20 日
out1 = [cell1,cell2,cell3,cell4,cell5];
cell0 = out1(~cellfun('isempty',out1));
Nouman Ashraf
Nouman Ashraf 2015 年 5 月 20 日
編集済み: Walter Roberson 2015 年 5 月 20 日
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global i
i=1
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global i
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Enter your name'};
dlg_title = 'Name';
num_lines = 1;
def = {'','hsv'};
answer=inputdlg(prompt,dlg_title,num_lines,def)
i=i+1
i am executing this above code. every time user press push button 2 enter his name and store its name into answer. but instead of updating the answer it empties the previous names and just store the last name. how can i store every name into answer when user press push button 2 and enter his name. push button 1 is just to initialize i
Walter Roberson
Walter Roberson 2015 年 5 月 20 日
Your variable "answer" exists only within the workspace of the callback function, and is destroyed afterwards. If you want the information to be remembered you need to store it somewhere else. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
Nouman Ashraf
Nouman Ashraf 2015 年 5 月 20 日
i cant get it into working can you help me with the code
Walter Roberson
Walter Roberson 2015 年 5 月 20 日
handles.answer = answer;
guidata(hObject, handles);
Then, in another routine where you wanted to use the value,
answer = handles.answer;

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

質問済み:

2015 年 5 月 20 日

コメント済み:

2015 年 5 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by