Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Nipurn Gulgulia
Nipurn Gulgulia le 16 Fév 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

Réponses (1)

Walter Roberson
Walter Roberson le 16 Fév 2018
Modifié(e) : Walter Roberson le 16 Fév 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 commentaires
Nipurn Gulgulia
Nipurn Gulgulia le 16 Fév 2018
Modifié(e) : Nipurn Gulgulia le 16 Fév 2018
Sorry I am not getting it!! Can you explain or show me !
Walter Roberson
Walter Roberson le 16 Fév 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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by