Movie function with subplots: error "Unrecognized method, property..."

1 次查看(过去 30 天)
I am trying to create an animation for different data frames, I keep getting the error:
Unrecognized method, property, or field 'cdata' for class 'matlab.ui.Figure'.
Error in plotSpectrum_insideKHI (line 729)
[h, w, p] = size(f(1).cdata); % use 1st frame to get dimensions
The full code:
% Frame to plot
frame = 22;
xStart = [257 257 257];
xEnd = 340*[1 1 1];
% Get the range in x of the values we want to consider
% Load X and Y data
XX = load([upperDir subDir1 'X.txt']);
YY = load([upperDir subDir1 'Y.txt']);
% Make the Fourier mesh
n = size(XX);
dx = XX(2,1) - XX(1,1);
dy = YY(1,2) - YY(1,1);
L(1) = max(max(XX)) + dx;
L(2) = max(max(YY)) + dy;
% Make a vector for x direction
xVec = XX(:,1);
yVec = YY(1,:)';
% Make a vector for ky
kyVec = makeK(L(2), n(2))*1000;
kyVec = kyVec(1:n(2)/2);
maxkx = 0;
minkx = 1e11;
fontSize = 16;
f = figure(1);
f.Position=[65 213 1170 530];
f.Renderer= 'Painters';
for i = 1:2
hAxis(i) = subplot(1,2,i);
end
w = [305 175 125];
% w = 305; % [305 205 375];
kx = linspace(minkx, maxkx, 1000);
ky = linspace(kyVec(2), kyVec(end), 1000);
% colors = {'b-','r-','m-'};
M(frame) = struct('cdata',[],'colormap',[]);
for i = 1:length(frame)
% Make a vector for kx
kxVec = makeK( xVec(xEnd(1)) - xVec(xStart(1)) + dx, 2^(nextpow2(xEnd(1) - xStart(1) +1)))*1000;
kxVec = kxVec(1:length(kxVec)/2);
maxkx = max([ maxkx kxVec(end)]);
minkx = min([ minkx kxVec(2)]);
% Load density data
%test: load data from one folder and loop over frames 1:22
ne_bg = load([upperDir subDir1 'ne_unpert.txt']);
ne = load([upperDir subDir1 'ne' num2str(frame) '.txt']);%[upperDir '/ne_' num2str(frame) '.txt']);
ne_p = ne - ne_bg ;
phi_bg = load([upperDir subDir1 'phi_unpert.txt']);
phi = load([upperDir subDir1 'phi' num2str(frame) '.txt']);
phi_p = phi - phi_bg ;
dn_over_n = ne_p ./ ne;
% % Take fft in x direction and integrate in y direction to get spectrum
dn_spectrum_x = FFTmat(dn_over_n(xStart(1):xEnd(1), :), yVec, 2, 1)';
phi_spectrum_x = FFTmat(phi_p(xStart(1):xEnd(1), :), yVec, 2, 1)';
% % Take fft in y direction and integrate in x direction to get spectrum
dn_spectrum_y = FFTmat(dn_over_n(xStart(1):xEnd(1), :), xVec(xStart(1):xEnd(1)), 1, 1)';
phi_spectrum_y = FFTmat(phi_p(xStart(1):xEnd(1), :), xVec(xStart(1):xEnd(1)), 1, 1)';
subplot(1,2,1);
loglog(kyVec(2:end), dn_spectrum_y(2:end));
hold on;
grid on;
subplot(1,2,2);
loglog(kyVec(2:end), phi_spectrum_y(2:end));
hold on;
grid on;
M(i) = getframe(f);
end
[h, w, p] = size(f(1).cdata); % use 1st frame to get dimensions
hf = figure;
% resize figure based on frame's w x h, and place at (150, 150)
set(hf, 'position', [150 150 w h]);
axis off
movie(hf,f);
mplay(f)
I am trying to get an animation of subplots simultaneously.

采纳的回答

KSSV
KSSV 2021-10-18
Try replacing the line:
[h, w, p] = size(f(1).cdata); % use 1st frame to get dimensions
with
[h, w, p] = size(M(1).cdata);
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by