When using inputdlg with str2double, Matlab hangs if a number is entered without a nonzero decimal
Show older comments
Hello, I'm new to asking questions, but am pretty familiar with Matlab, and I have no idea why this is happening. I am writing a program that will take data from an IMU and calculate things like speed and angular position for my job, so the names of variables and comments have been modified slightly, because legal reasons. I'm using R2013a by the way.
In order to make the program consistent, I setup an automatic motion detection, but because of the object I'm measuring, the data has large portions of no motion. To keep my automatic detection, I instead implemented a dialogue box that prompts the user to input a time just before an event they want to analyze. To do this, I draw a fullscreen plot of the data from one of the gyroscopes, and make a pop-up window appear asking for input. This is where I have my problem:
%Semi-automatic movement detection, finds indices where the gyro reading crosses
%the threshold after the time specified by the user
fig=figure('Name','Event Locator','units','normalized','outerposition',[0 0 1 1]);
plot(time,xgyro);
xlabel('Time (s)');
ylabel('Angular Velocity (deg/s)');
title('Corrected Angular Velocities');
legend('Xgyro','Location','northwest');
%popup window asking for a time just before the event you want to analyze
prompt = 'Enter a time just before the event you want to analyze: ';
t=str2double(inputdlg([prompt,'Event Timing']));
drawnow;
pause(0.5);
waitfor(t);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
close(fig);
All of the variables are defined in earlier m-files, and everything works perfectly if the number entered has a nonzero decimal (ie, 5.1,3.000000000001,2.9 - but not 7 or 6.0). If a nonzero decimal is entered the program continues on its merry way, but if it isn't then the dialog box closes, the figure doesn't close, and if I force the code to stop, it tells me the code was stopped on the line I indicated with the <<<<<.
Has anyone seen this before, or does anyone know why this is happening? I'd greatly appreciate any help I can get. I've tried to fix it with the ol "drawnow and pause" trick, but to no avail.
Cheers,
Conlan
2 Comments
Adam
on 30 Sep 2015
I tried the part of your code from with just opening a figure, running the prompt and closing it and it works fine for me with values like 7 or 6.0.
Conlan Kirk
on 30 Sep 2015
Edited: Conlan Kirk
on 30 Sep 2015
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!