Why am I getting a NaN value when calling a variable using uicontrol?

조회 수: 25 (최근 30일)
Bradley
Bradley 2024년 12월 5일 23:09
댓글: Bradley 2024년 12월 6일 14:00
Im building an app for work and at the end I want to have the average speed of a vehicle shown in a box after pressing run. I have speed data, and I took the average using this line of code:
AvgSpeed1 = mean(RealSpeed1);
Pretty simple. It should give me a value around 2.5. I have a couple uipanels, one of which is called panel2, and I created this block of code to generate the text after the run button is pressed:
avgSpeed = uicontrol(panel2, "Style", "text");
avgSpeed.Position = [10 50 200 20];
avgSpeed.FontSize = 10;
At the end of the run function I have this line of code to generate the text within the box:
avgSpeed.String = sprintf("Average Speed: %.3f", AvgSpeed1);
After pressing the run button I get this result:
As you can see the result I get for average speed is NaN, but I have this exact setup for a few other variables like final run time and the time taken to process the data without issue. The code for these other two is exactly the same as the average speed. What im confused about is why im getting a NaN value, I checked the data within my vairables and do not have any NaN values, so im wondering if im missing any syntax or if Im doing this incorrectly. Any help is appreciated. Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2024년 12월 5일 23:23
Try
AvgSpeed1 = mean(RealSpeed1, "omitmissing");

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by