I'm using GNU Octave, version 4.4.1. I'm trying to make an interactive plot of a simple oscillator by including two sliders which would allow the initial velocity and oscillator mass to be changed.
The plot itself shows fine, as well as the script with one slider (for velocity). Here's a part of that script with the callback function:
function titranje_ia1 (hslider, event)
v0 = get ( hslider, "value" );
m = 1;
k = 1;
t = 0:0.1:30;
x = v0*sin(sqrt(k/m)*t);
axes ('position', [0.1, 0.2, 0.8, 0.75]);
h = plot ( t, x );
axis ([0 30 -11 11]);
set (h, "linewidth", 2);
set (gca, "xlabel", "t (s)", "ylabel", "x (m)", "fontsize", 12);
set (gca, 'XTick', 0:pi:10*pi)
set (gca, 'XTickLabel', {'0','pi','2pi','3pi','4pi','5pi','6pi','7pi','8pi','9pi','10pi'})
grid on;
l = legend (sprintf('v0 = %f', v0));
set (l, "fontsize", 12)
endfunction
However, when I include a second slider
function titranje_ia2 (hslider1, hslider2, event)
v0 = get ( hslider1, "value" );
m = get ( hslider2, "value" );
k = 1;
t = 0:0.1:30;
x = v0.*sin(sqrt(k./m).*t);
axes ('position', [0.1, 0.2, 0.8, 0.75]);
h = plot ( t, x );
axis ([0 30 -11 11]);
set (h, "linewidth", 2);
set (gca, "xlabel", "t (s)", "ylabel", "x (m)", "fontsize", 12);
set (gca, 'XTick', 0:pi:10*pi)
set (gca, 'XTickLabel', {'0','pi','2pi','3pi','4pi','5pi','6pi','7pi','8pi','9pi','10pi'})
grid on;
l = legend (sprintf('v0 = %f', v0));
set (l, "fontsize", 12)
endfunction
I receive an error:
error: titranje_ia2: product: nonconformant arguments (op1 is 0x0, op2 is 1x301)
execution error in graphics callback function
Since I know that 'k' is a scalar and 't' a vector (but I'm not sure what v0 and m would be; I suppose scalars), I included an elementwise operations in function 'x' definition. 't' size is 1x301, so I assume that 'sqrt(k./m)' is 0x0 (as seen by Octave). Shouldn't it be 1x1?
Indeed, when I try
size(m)
I receive ans = 0 0 (for size(v0) I get ans = 1 1). Could it be that there is a problem with slider definition? I include at the end both slider definitions:
%Definiramo ui element: 'klizac' za v0
hslider1 = uicontrol (
"style", "slider",
"units", "normalized",
"position", [0.1, 0.0, 0.8, 0.1],
"min", 1,
"max", 10,
"value", 4,
"callback", @titranje_ia2
);
%Definiramo ui element: 'klizac' za m
hslider2 = uicontrol (
"style", "slider",
"units", "normalized",
"position", [0.1, 0.05, 0.8, 0.1],
"min", 1,
"max", 10,
"value", 1,
"callback", @titranje_ia2
);
Thank You in advance!
Best regards,
Igor