Continuously update MATLAB surf plot and animate it

14 Ansichten (letzte 30 Tage)
Ahmad Lakhani
Ahmad Lakhani am 22 Sep. 2017
Beantwortet: Star Strider am 22 Sep. 2017
I have the following loop that plots and re-plots data in MATLAB using thesurf() function. How do I get the plot to update while the values are changing and how do I animate it?
s = 1;
timerID = tic;
while true
if(toc(timerID) > 25)
break;
end
for i=1: 5
removeChannel(session, 7)
addAnalogInputChannel(session,'cDAQ1Mod8',['ai' num2str(i+15)],'Voltage');
for j=1: 5
measurements(6-j,6-i) = abs(session.inputSingleScan) - abs(base);
end
end
surf(interp2(flipud(abs(measurements)),4));
view(0, 90);
colorbar;
pause(0.05)
s = s+1;
end

Akzeptierte Antwort

Star Strider
Star Strider am 22 Sep. 2017
I am not certain exactly what you want to do, and I cannot run your code to test this with it.
See if this example offers some idea on how to do what you want:
[X,Y] = meshgrid(linspace(-15, 15, 50));
fcn = @(x,y,k) k*x.^2 + y.^2;
v = [1:-0.05:-1; -1:0.05:1];
for k1 = 1:2
for k2 = v(k1,:)
surfc(X, Y, fcn(X,Y,k2))
axis([-15 15 -15 15 -300 500])
drawnow
pause(0.1)
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by