Setting a textbox returning error 'Unable to resolve the name'

2 次查看(过去 30 天)
I have a GUI function that defines a few text boxes under the structure S. When calling to update the value of the text box named 'S.Text_for_display' within a seperate function called 'Speak' I recive the error 'Unable to resolve the name 'S.Text_for_display'.'.
function []=Speak(txt)
set(S.Text_for_display,'String','','LineStyle','none','FontSize',14,'FontName','Comic Sans... MS','FitBoxToText','off');
len=length(txt);
for i=1:len;
if i<=len;
Display(txt(1:i));
pause(.05);
else
Display(txt);
end
end
end
  1 个评论
Walter Roberson
Walter Roberson 2024-1-20
for i=1:len;
if i<=len;
Display(txt(1:i));
pause(.05);
else
Display(txt);
end
In a for loop that goes 1:len it is certain that i <= len so there is no point in having the if

请先登录,再进行评论。

回答(1 个)

Dyuman Joshi
Dyuman Joshi 2024-1-18
编辑:Dyuman Joshi 2024-1-19
The function does not know what "S" is. You need to pass it as an input.
And the font name 'Comic Sans MS' does not have ellipses (3 dots) in it.
%For cross-check
listfonts
ans = 14×1 cell array
{'Arial' } {'Arial Black' } {'Arial Narrow' } {'Comic Sans MS' } {'Courier' } {'Courier New' } {'Georgia' } {'Helvetica' } {'Impact' } {'Terminal' } {'Times' } {'Times New Roman'} {'Trebuchet MS' } {'Verdana' }
  4 个评论
lewis williamson
lewis williamson 2024-1-19
Ok, I'm still not sure how to parse the acutal textbox into the function here. If i try running your fucntion you have provided It does not recognise the textbox: 'method, property, or field 'Text_for_display' for class 'matlab.graphics.shape.TextBox''
Dyuman Joshi
Dyuman Joshi 2024-1-20
Could you share the struct "S"? Use the paperclip button to attach.
How are you calling the function?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by