Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Nipurn Gulgulia
Nipurn Gulgulia am 16 Feb. 2018
Bearbeitet: Walter Roberson am 16 Feb. 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

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by