"Invalid color or line style." Error during plotting in Executable

I am trying to plot a figure with an executable created by "compiler.build.standaloneApplication".
The function I am using is;
function dummyFunction1(a,b)
plot([1 2],[a b]);
end
And the code for executable generation;
appFile = fullfile('D:\testFolder\dummyFunction1.m');
opts = compiler.build.StandaloneApplicationOptions(appFile,'OutputDir','D:\testFolder');
results = compiler.build.standaloneApplication(opts);
Here is the problem;
Any help would be great.

 채택된 답변

Steven Lord
Steven Lord 2023년 6월 23일

0 개 추천

Read the "Using a MATLAB File You Plan to Deploy" section on this documentation page. Inside your application as you've written it a and b are not the numbers 5 and 8 but the char arrays '5' and '8', and '58' is not a valid color or line style for the plot function (as the error message indicates.) You will need to convert them into numbers before using them in your call to plot.

댓글 수: 3

Hi Steven, thank you. The link helps me to modify the function.
The key point is command prompt takes inputs as a character array.
function dummyFunction1(a,b)
a_double = str2double(a);
b_double = str2double(b);
plot([1 2],[a_double b_double]);
end
You probably want to use the isdeployed function to only convert from string to number in your deployed application, or use the ischar and/or isstring function to only convert if you receive text data as input. If given a number as input the str2double function will return NaN.
str2double(5)
ans = NaN
x = '5';
if ischar(x)
fprintf("Input data is a char")
x = str2double(x);
else
fprintf("Input data is a number")
end
Input data is a char
class(x)
ans = 'double'
x = 8;
if ischar(x)
fprintf("Input data is a char")
x = str2double(x);
else
fprintf("Input data is a number")
end
Input data is a number
class(x)
ans = 'double'
It is realy helpful, thank you.

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

추가 답변 (1개)

GAJENDRA TELI
GAJENDRA TELI 2023년 6월 23일

0 개 추천

you should check the color or line style in dummyFunction1 and change both by some other vlue and then run the program and check the output result.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 6월 23일

댓글:

2023년 6월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by