How to solve "Inf" from table calculation in GUI
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all. I tried to make vehicle velocity calculation with 2 tables input. table 1 is 1st CCTV time captured the vehicle and table 2 is 2nd CCTV time captured the vehicle.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1401759/image.png)
then I made a code like this:
data=handles.data;
xtes=data(1:5,2);
ytes=data(1:5,2);
time=xtes-ytes;
velocity=5./time;
handles.velocity=velocity;
set(handles.uitable3,'Data',velocity);
guidata(hObject,handles);
but after I ran it, why the calculation result is turn out "Inf". How can I solve this? Thank you very much!
0 件のコメント
回答 (2 件)
Walter Roberson
2023 年 6 月 3 日
your xtes and ytes are exactly the same so subtraction gives 0.
2 件のコメント
Image Analyst
2023 年 6 月 10 日
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
Diwakar Diwakar
2023 年 6 月 3 日
The issue you're experiencing where the calculation result is turning out as "Inf" is likely due to dividing by zero. In your code, you're calculating the time difference between two time values (xtes and ytes), and then calculating the velocity by dividing a constant value of 5 by the time difference.
If the time difference between xtes and ytes is zero for any row in the table, it will result in division by zero, which produces "Inf" as the result.
Try this code
data = handles.data;
xtes = data(1:5, 2);
ytes = data(1:5, 2);
time = xtes - ytes;
time(time == 0) = eps; % Replace zero values with a small positive value
velocity = 5 ./ time;
handles.velocity = velocity;
set(handles.uitable3, 'Data', velocity);
guidata(hObject, handles);
1 件のコメント
Walter Roberson
2023 年 6 月 3 日
xtes = data(1:5, 2);
ytes = data(1:5, 2);
Notice that those right hand sides are exactly the same, so xtes will exactly equal ytes in all positions.
参考
カテゴリ
Help Center および File Exchange で Classification Ensembles についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!