The msgbox pops up here, but when I click OK, the graph doesn't appear. Why?

1 view (last 30 days)
hm = msgbox('To calibrate pick up three non-collinear points');
waitfor(hm)
X = ones(3, 3);
S = zeros(3, 2);
prompt = {'Enter actual angle value, deg',...
'Enter actual lever value, m'};
numlines = 2; defaultanswer = {'', ''};
options.Resize = 'on';
options.WindowsStyle = 'normal';
options.Interpreter = 'tex';
for k = 1:3
[ xs, ys ] = ginput(1);
S(k, 1) = xs;
S(k, 2) = ys;
name = [ 'Point ' num2str(k) ];
Actual = inputdlg(prompt, name, numlines, defaultanswer, options);
X(k, 1) = str2double(Actual{1});
X(k, 2) = str2double(Actual{2});
end
C = X\S;
hm = msgbox('Start digitizing from zero to maximum heel');
waitfor(hm)
DIG = ones(2, 1); % initialize array of coordinates of the
% digitized points
l = 1; % initialize counter of digitized points
button = 'Yes'; % initialize loop sentinel
while strcmp(button, 'Yes')
[ xd, yd ] = ginput(1);
plot(xd, yd, 'r.') % mark digitized point
DIG(1, l) = xd;
DIG(2, l) = yd;
l = l+ 1;
qstring = [ 'Digitize point ' num2str(l) ];
button = questdlg(qstring, 'Digitizing');
end
hold off
[ m, n ] = size(DIG);
REAL = zeros(2, n); % allocate space for real-world
% coordinates of digitized points
A2 = C(1:2,:)'; C2 = C(3, :)'*ones(1, n); B2 = DIG - C2;
REAL = A2\B2; % returns real-world coordinates of
% digitized points
phi = REAL(1, :); % real-word heel-angle values, degrees
phi(1) = 0;
GZ = REAL(2, :); % real-world righting-lever values
GZ(1) = 0;
phir = pi*phi/180; % real-world heel-angle values, radians
phii = 0: 2.5: max(phi); % axis for spline interpolation
GZi = spline(phi, GZ, phii); % interpolated values
l = length(GZi); GZl = GZi(1: (l-1)); S1 = [ 0 cumsum(GZl) ];
GZ2 = GZi(2: l); S2 = [ 0 cumsum(GZ2) ]; S = (pi*2.5/(2*180))*(S1 + S2);
% Choose mode of entering GM
LS = [ {'Numerical value of GM known'},...
{'GM to be picked up on graph'},...
{'GM unknown'} ];
[ Selection, ok ] = listdlg('Liststring', LS, 'SelectionMode','Single');
switch Selection
case 1
% begin arguments of input dialogue
prompt = {'Enter GM value in m'};
numlines = 1;
defaultanswer = {''};
options.Resize = 'on';
options.WindowsStyle = 'normal';
options.Interpreter = 'tex';
% end arguments of input dialogue
GMstring = inputdlg(prompt, name, numlines, defaultanswer, options);
GM = str2double(GMstring);
case 2
[ xd, yd ] = ginput(1);
Bgm = [ xd; yd ] - C(3, :)';
GMphi = A2\Bgm; % returns real-world coordinates
GM = GMphi(2);
case 3
GM = 0;
end
figure(2) = ploty(phii, GZi, phii, S);
if GM > 0
hold on
axis([ 0 1.1*max(phii) 0 1.1*GM ])
t = [ 'GM = ' num2str(GM) ' m' ];
text(185/pi, GM, t)
hold off
end
title([ 'Curves of statical and dynamical stability for file ' filename ])
xlabel('Heel angle, deg')
set(get(Ax(1), 'Ylabel'),'String','Lever arms, m')
set(get(Ax(2),'Ylabel'),'String','Area under curve, m \cdot rad')
SSCURVE = GZi;
AREAS = S;
fid = fopen('scdigitizer.out', 'w');
fprintf(fid, 'Curves of statical and dynamical stability\n');
fprintf(fid, 'calculated with the function SCDIGITIZER\n');
fprintf(fid, 'for file %s \n', filename);
fprintf(fid, ' Heel angle GZ Area\n');
fprintf(fid, ' Degrees m m.rad\n');
for k = 1:l
fprintf(fid, '%10.1f %10.2f %10.3f \n', phii(k), GZi(k), S(k));
end
fclose(fid)
and
The msgbox pops up here, but when I click OK, the graph doesn't appear. Why?
function [ SSCURVE, AREAS ] = scdigitizer(filename)
if nargin < 1
[ filename, pathname ] = uigetfile({'*.jpg'; '*.gif'; '*.bmp'; '*.tif'},...
'Select a graphic input file');
end
A = imread(filename);
him = image(A);
axis off
grid
hold on
And if I add this code at the beginning, when I save it as a MATLAB code file, I can't see anything in the selection window when I run it. What should I do?

Answers (1)

Image Analyst
Image Analyst on 23 Nov 2020
You forgot to say
hold on
after your first call to plot() so, because of that, each point you plot blows away the prior point you plotted.

Community Treasure Hunt

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

Start Hunting!