How can I pass a variable (numeric) through a callback event when I pressed a key in my figure?

1 回表示 (過去 30 日間)
Guilherme  Lima
Guilherme Lima 2021 年 10 月 20 日
編集済み: Guilherme Lima 2021 年 10 月 21 日
Hello,
I have an issue;
I am collecting data in a while loop and I want to store this data in my callback event when I press a key in my figure.
This does not work at all.
Could you please help me in this topic?
My code example:
set(gcf, 'KeyPressFcn', {@GetData, calibration});
while true
pause(0.00001);
[calibration] = ml_CANapeReadCalibrationObject(moduleHandle(1,2), 'F_DE_f_1', 1);
sensorData = [sensorData; calibration(1)];
plot(sensorData);
drawnow;
disp('getting data');
end
function GetData(src, event, sensorData)
finalData = [finalData; sensorData];
pause(1);
end
  2 件のコメント
Jan
Jan 2021 年 10 月 20 日
This piece of code is not running. It is not clear if the callback is a nested function or not. "Does not run at all" is not useful to explain the problem. Do you get an error message?
Guilherme  Lima
Guilherme Lima 2021 年 10 月 21 日
編集済み: Guilherme Lima 2021 年 10 月 21 日
There is the following error message
Undefined function or variable 'finalData'.
Error in FinalVersion_lateral_FoV>GetData (line 155)
finalData = [finalData; sensorData];
Error while evaluating Figure KeyPressFcn.
What is happening is that my variable sensorData is empty inside the function.
In the loop while, the variable sensroData is receving the value properly, but when I press some button in the keyboard, the function GetData is not getting the value that is in the variable sensorData.
I hope that is clear now. Please, let know if it is not.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by