필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Nipurn Gulgulia
Nipurn Gulgulia 2018년 2월 16일
편집: Walter Roberson 2018년 2월 16일
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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 16일
편집: Walter Roberson 2018년 2월 16일
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
Nipurn Gulgulia
Nipurn Gulgulia 2018년 2월 16일
편집: Nipurn Gulgulia 2018년 2월 16일
Sorry I am not getting it!! Can you explain or show me !
Walter Roberson
Walter Roberson 2018년 2월 16일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by