Clear Filters
Clear Filters

I was trying to add errors messages if theres error in user input but I ended up with two errors that I couldn't figure it out how to fix

1 view (last 30 days)
function CalculerButtonPushed(app, event)
x=app.ValeurdeXEditField.Value;
a=str2num(x);
y=app.fxEditField.Value;
b=str2num(y);
z=app.fdeX.Value;
c=str2num(z);
if (app.ValeurdeXEditField.Value==' ')||(app.fxEditField.Value==' ')||(app.fdeX.Value==' ')
errordlg("Les vecteurs doivent ",'ERREUR');
else
if size(a)== size(y)
n=length(a);
p0=0;
for i=1:n
L=1;
for j=1:n
if i~=j
L=L.*(c-a(j))/(a(i)-a(j));
end
end
p0=p0+(b(i).*L);
end
Y=p0;
app.ResultatdefxTextArea.Value=num2str(Y);
else
errordlg("Les vecteurs doivent etre de la meme taille ",'ERREUR');
end
end
this is the errors i get:
1)
Error in app2/CalculerButtonPushed (line 37)
if (app.ValeurdeXEditField.Value==' ')||(app.fxEditField.Value==' ')||(app.fdeX.Value==' ')
Error while evaluating Button PrivateButtonPushedFcn.
2)
Index exceeds the number of array elements even if i type the same array size

Answers (1)

prabhat kumar sharma
prabhat kumar sharma on 5 Oct 2023
Edited: prabhat kumar sharma on 5 Oct 2023
I understand you are facing issues in the button pushed call back function.
1. The error received in the line 37 is likely due to the syntax you are using. You can correct it by using the “isequal function as follows:
if isequal(app.ValeurdeXEditField.Value, ' ')|| isequal(app.fxEditField.Value, ' ') ||isequal(app.fdeX.Value, ' ')
errordlg("Les vecteurs doivent ",'ERREUR');
The “isequal” function is used to convert the operands to a logical scalar vector. For more information about the same, you can refer to the following documentation link:
2. On executing the provided code, I found another issue where you are trying to compare the sizes of “a” and “y”. Since “a” is a numeric array and “y” is a string array, the sizes will always be different and thus trigger the error dialogue. It can be rectified by comparing the sizes of variables “a” and “b”.
Making the above-mentioned changes resulted in smooth execution of the application.
I hope this helps!
Regards,
Prabhat Sharma
  1 Comment
Walter Roberson
Walter Roberson on 5 Oct 2023
I wonder if you should be testing
isempty(app.ValeurdeXEditField.Value) || isempty(app.fxEditField.Value) || isempty(app.fdeX.Value)
or perhaps isempty(strtrim(...))

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!