MATLAB Answers

Dot indexing is not supported for variables of this type when trying to write value into static text box

5 ビュー (過去 30 日間)
Samuel Leeney
Samuel Leeney 2020 年 10 月 16 日
回答済み: Image Analyst 2020 年 10 月 17 日
function text7_CreateFcn(hObject, eventdata, handles)
value=1;
set(handles.text7, 'String', num2str(value))
I am trying to add a value that will be determined by a slider in my GUI into the text of a static text box, but recieve the error message 'Dot indexing is not supported for variables of this type'

  3 件のコメント

Samuel Leeney
Samuel Leeney 2020 年 10 月 16 日
Any help on this would be much aprpeciated as it is the final part I am stuck on for a project, and have next to no help as teaching is 100% online. Thanks!
Samuel Leeney
Samuel Leeney 2020 年 10 月 17 日
No, it's created using guide, the older software. I'm not a fan of app designer.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 10 月 17 日
Do not put anything into the CreateFcn() functions of controls. If you want something to be initialized with a value, then put that value into the String property of the control in GUIDE, not in the CreateFcn.
Now, to get the value of a slider and put it in the text box as you move the slider, you'd put it into the callback function of the slider, not the callback of the text box.
function slider1_CallbackFcn(hObject, eventdata, handles)
value = handles.slider1.Value;
textLabel = sprintf('Slider = %.3f', value);
% Update text box
handles.text7.String = textLabel;

  0 件のコメント

サインインしてコメントする。

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2020 年 10 月 16 日
編集済み: Fangjun Jiang 2020 年 10 月 16 日
set(hObject, 'String', num2str(value))
see this comment ?
% hObject handle to edit1 (see GCBO)
% handles empty - handles not created until after all CreateFcns called

  4 件のコメント

表示 1 件の古いコメント
Rik
Rik 2020 年 10 月 17 日
The handles struct has not been created yet, so you need to use the handle to the object itself.
Also, do yourself a huge favor and don't use GUIDE for anything you spend more than 10 minutes making. Link
Samuel Leeney
Samuel Leeney 2020 年 10 月 17 日
Like this? set(handles, 'String', num2str(value))
Thanks, I actually tried migrating this across to app designer but it didn't go across properly. I will probably use app designer in the future. We have next to no support from the professor's this year due to the pandemic so have been making quite a few basic mistakes with stuff like this!
Rik
Rik 2020 年 10 月 17 日
No, set(hObject,'String',num2str(value)).
Using a programmatic GUI (and not AppDesigner) offers a wide variety of benefits. I would encourage you to check out the thread I linked in my previous comment.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2020 年 10 月 17 日
function text7_CreateFcn(hObject, eventdata, handles)
value = 1;
set(hObject, 'String', num2str(value))

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by