Matlab App Designer does not respond after running for ~15min
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I am relatively new to Matlab and I'm trying to use several sensors to measure temperature, pressure etc.
Therefor I use the Arduino Mega2560. In the Arduino IDE I read out the measured values. In Matlab App Designer I use the Serial-API to get the values.
In the app the measured values are displayed in diagrams and can be saved after pressing a button.
After running the code for about 15-20 minutes the program doesn't respond any more, e.g. pressing a button does not cause any action any more. Additional I am not able to close the window at all.
I need to execute those actions, because the measurement has to run for about 20 minutes and than I have to stop the code, so that the values get stored in a file.
Thanks! I hope someone can help me :)
Here is my code: (for only one sensor for easier understanding)
function startupFcn(app)
% Arrays for saving values
vals1 = [];
saveButton = 0;
% Initalizing Diagrams
app.UIAxesTemp.XLim = [0 100];
app.UIAxesTemp.YLim = [0 70];
% variable to check if any values are in the arrays already
valuesInArray = 0;
% variable to see if values should be saved already
savevalues = 0;
% variable to see if a file alrady have been saved
filesaved = 0;
% variable to claim which sensor should be read
neededSensor = 0;
% variables for getting time
t1 = now;
t11 = datevec(t1);
% Initializing Serial-API
delete(instrfind({'port'},{'COM7'}));
s=serial('COM7', 'BaudRate', 9600, 'Terminator','CR');
fopen(s);
while app.StopProgram.Value == 0
%Read data
data = fscanf(s);
temp = string(data);
t2 = now;
t22 = datevec(t2);
time = etime(t22,t11);
if regexp(temp, "[0-5] {1,}[0-9]{1,}.[0-9]{1,}") %format of output of Arduino IDE
% sensorNr: the number of the sensor, from which the
% value is coming
sensorNr = cast(extractBetween(temp, 2, 2), 'double');
value = cast(regexp(temp, '([0-9]{1,}.[0-9]{1,})', 'match'), 'double');
switch neededSensor
case 1
app.Sensor2TemperaturinCEditField.Value = value;
hold(app.UIAxesTemp, 'on');
s2 = plot(app.UIAxesTemp,time,wert,'xm');
if saveButton == 1
vals1 = [vals1; value];
valuesInArray = 1;
end
% case 2,3,4 etc. (for more sensors)
saveButton = app.SpeichernButton.Value;
end
%needed sensor count up (doesnt matter for this problem)
else
disp("No data found.");
end
fileName = app.FileNameEditField.Value;
%Look if there are values in the Arrays, if the saveButton
%is deactivated again and if the file hasn't been saved yet.
if valuesInArray == 1 && saveButton == 0 && fileSaved == 0;
finalData = [vals1]; %other arrays for more sensors
writematrix(fin, strcat('C:\Users\[...]',fileName,'.xlsx'));
fileSaved = 1;
end
pause(0.1);
end
close(app.UIFigure);
end
댓글 수: 0
답변 (1개)
Michael Van de Graaff
2022년 1월 17일
You have an fopen but no fclose. that's generally not a great idea in my experience
Is fopen even supposed to be used in this context?
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!