Borrar filtros
Borrar filtros

How to add multiple rows in Edit Text box from a list?

3 visualizaciones (últimos 30 días)
Nipurn Gulgulia
Nipurn Gulgulia el 16 de Feb. de 2018
Editada: Walter Roberson el 16 de Feb. de 2018
I am trying to add strings into a edit text box using a list of strings. But after adding two lines i am getting error "Error using horzcat, Dimensions of matrices being concatenated are not consistent."
% code
as.SignalEdit = uicontrol(as.parent,'Style','edit',...
'Units','normalized', 'Position', [0.405, 0.01, 0.6, 0.875]);
set(as.SignalEdit,'Max',10000);
%call back function
function addSignal(as,source,~)
SignalList = evalin('base','SignalList');
exist_strings = get(as.SignalEdit,'String');
All_Signals = get(as.SignalListBox,'String');
SelectedSignalValue = get(as.SignalListBox,'Value');
txt = sprintf ([exist_strings, '\n' ,All_Signals{SelectedSignalValue},' =']);
set(as.SignalEdit,'String',[txt,'']);
end

Respuestas (1)

Walter Roberson
Walter Roberson el 16 de Feb. de 2018
Editada: Walter Roberson el 16 de Feb. de 2018
When you set() the string of an edit with max greater than one, then it splits the entries at newlines or | and creates a cell array of strings from them. You then run into concatenation problems.
Initialize your string property to {} . Then each time you go to add a new line, fetch the string property (which will be cell) and variable{end+1} = new string and store that back
  2 comentarios
Nipurn Gulgulia
Nipurn Gulgulia el 16 de Feb. de 2018
Editada: Nipurn Gulgulia el 16 de Feb. de 2018
Sorry I am not getting it!! Can you explain or show me !
Walter Roberson
Walter Roberson el 16 de Feb. de 2018
as.SignalEdit = uicontrol(as.parent,'Style','edit',...
'Units','normalized', 'Position', [0.405, 0.01, 0.6, 0.875], 'Max', 10000, 'String', {});
function addSignal(as,source,~)
All_Signals = get(as.SignalListBox,'String');
SelectedSignalValue = get(as.SignalListBox,'Value');
new_signal = All_Signals{SelectedSignalValue};
signal_list = get(as.SignalEdit,'String');
signal_list{end+1} = new_signal;
set(as.SignalEdit, 'String', signal_list);

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by