Clear Filters
Clear Filters

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

3 views (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 16 Feb 2018
Edited: Walter Roberson on 16 Feb 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 Comments
Nipurn Gulgulia
Nipurn Gulgulia on 16 Feb 2018
Edited: Nipurn Gulgulia on 16 Feb 2018
Sorry I am not getting it!! Can you explain or show me !
Walter Roberson
Walter Roberson on 16 Feb 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);

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!