making a title using editable strings without stacking

조회 수: 3 (최근 30일)
Greg Morris
Greg Morris 2019년 6월 17일
댓글: Walter Roberson 2019년 6월 19일
So, I have this GUI that takes a excel sheet, or CSV file and plots the data inside the sheet. On top of that I have edit boxes that creste labels on the plot of the GUI. The plotting works and the label making works, but I have a check box that add elements to the tile based off what your labels are. saddly, the lements instead of rweading out in one line, stack ontop of eachother
Capture.PNG
and the code is such
function Excel_Button_Callback(hObject, eventdata, handles)
numdata=xlsread(uigetfile({'.xlsx'},'File Selector'))
x=numdata(:,1);
y=numdata(:,2);
plot(x,y);
xlabel(get(handles.X_Label_Input, 'String'));
ylabel(get(handles.Y_Label_Input, 'String'));
title(get(handles.Title_Input, 'String'));
if (get(handles.VsCheck, 'Value'))==1;
title([get(handles.Title_Input, 'String') get(handles.Y_Label_Input, 'String') 'vs' get(handles.X_Label_Input, 'String') date]);
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 6월 19일
Where is date coming from and what datatype is it? I predict it is string()
Shubham Gupta
Shubham Gupta 2019년 6월 19일
I think "date" here is an inbuild MATLAB function which gives current date string as an output

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

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 6월 19일
In the code you have shown the second to last line as
title([get(handles.Title_Input, 'String') get(handles.Y_Label_Input, 'String') 'vs' get(handles.X_Label_Input, 'String') date]);
"get" will give you cell array and then you are trying to concatenate cell as a string but instead MATLAB is concatenating it as a cell array. So, to resolve this you can try using "strjoin" to covert cell into string and then concatenate. For more info on "strjoin" you can use:
help strjoin
To get the expected results replace 2nd to last line with the line below :
title([strjoin(get(handles.Title_Input, 'String')),strjoin(get(handles.Y_Label_Input, 'String')),...
'vs',strjoin(get(handles.X_Label_Input, 'String')),date]);
I hope it helps!
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 6월 19일
""get" will give you cell array "
Possibly. But if so then one of two circumstances would have to be true:
  1. handles.Title_Input would have to be a vector of handles instead of a single handle; or
  2. handles.Title_Input would have to have Max > 1 so that it was a multi-line edit box.
When you get the String property of a single uicontrol for which Max is 1, then you get back a character vector

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by