How can I open a hyperlink from a button callback in AppDesigner?

조회 수: 1 (최근 30일)
Johannes
Johannes 2024년 2월 15일
편집: Johannes 2024년 2월 22일
I am creating an app where I would like to access information via an Edit field and a button. The user can write a specific number (system code) in the EditField and read information in a UITable below. For further reading I'd like to implement a button that calls the webpage where the PDF with additional information is stored. The links to the webpages regarding the selected code are stored as strings in an Excel file. So far I can access the right links as strings but I struggle to call the actual website. So far I have tried the "web" and "webpage" functions.
Initialization of public properties:
properties (Access = public)
links = readtable("guide_filling_code_neu_2.xlsx", 'Range', 'K1:K87','PreserveVariableNames', true);
codeguide = readtable("guide_filling_code_neu_2.xlsx", 'Range', 'A1:J87', 'PreserveVariableNames', true);
end
In the button callback function:
filling_code = app.SearchforfillingcodeEditField.Value;
r_1 = ismember(app.codeguide.('Filling Code'),filling_code); %Ermittlung der richtigen Reihe nach Eingabe
row = find(r_1);
linkstring = app.links(row,:);
linkstring = string(linkstring{:,:});
web(linkstring,'UniformOutput', false)
The execution brings the error
Error using web
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in guide_filling_system/DetailsPDFButtonPushed (line 1445)
web(linkstring,'UniformOutput', false)
  댓글 수: 2
Fangjun Jiang
Fangjun Jiang 2024년 2월 16일
Can you paste the value of linkstring when web() is executed? I am suprised by the error message because no output is needed.
Johannes
Johannes 2024년 2월 22일
Yes I have tried that in a test script. value of linkstring is the URL as a string

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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 2월 16일
편집: Cris LaPierre 2024년 2월 16일
I get an error when using the command you shared
linkstring = 'https://www.mathworks.com';
web(linkstring,'UniformOutput', false)
Error using web
First argument must be text.
If I make the input argument a string, I do not.
web(linkstring,'UniformOutput', 'false')
However, I'm not sure you even need that name-value pair. At least, I can't find it documented for this function. Why not just use web(linkstring)?
One concern I would have is this code
linkstring = app.links(row,:);
linkstring = string(linkstring{:,:});
We can't see what your variable values are, but a url should not span multiple colums. If this is a workaround because your url is a character array, I suggest using the "TextType","string" option in readtable instead.
  댓글 수: 5
Johannes
Johannes 2024년 2월 22일
Thank ypu for your answer. I tried the code without UniformOutput in a Test script using the mathworks-URL and it worked. So it must be something about the string I am trying to import from Excel. However, if I call the right cell from the table, the TextType does not make it a string. It`s still a 1x1 table.
Johannes
Johannes 2024년 2월 22일
편집: Johannes 2024년 2월 22일
I have just found my error. The find function does not return anything, so the table is empty. This is because my input field is a text field and the numbers compared in the Excel file are doubles. Str2double fixed the issue.
filling_code = str2double(app.SearchforfillingcodeEditField.Value);
r_1 = ismember(app.codeguide.('Filling Code'),filling_code); %Ermittlung der richtigen Reihe nach Eingabe
row = find(r_1);
linkstring = app.links(row,:);
linkstring = linkstring{1,1};
web(linkstring)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by