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.
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!