There's a mismatch in the data requirement of "griddata" function, you can read about it in documentation:
I have worked on the code and modified like this:
% Define a more diverse set of coordinates to avoid collinearity
a = [-90, -70, -50, -30, 20, 40, 60, 80]; % X座標
b = [-90, -80, -60, -40, 10, 30, 50, 70]; % Y座標 (changed to avoid collinearity)
% Calculate Z座標, converting degrees to radians
c = sin(deg2rad(a)) + cos(deg2rad(b));
% Create grid for contour plot
[aq, bq] = meshgrid(linspace(-90, 80, 100), linspace(-90, 80, 100));
% Interpolate data using cubic spline
cq = griddata(a, b, c, aq, bq, 'cubic');
% Debugging outputs
disp('Size of aq:');
disp(size(aq));
disp('Size of bq:');
disp(size(bq));
disp('Size of cq:');
disp(size(cq));
% Check dimensions
if isempty(cq) || any(isnan(cq(:))) % Check if cq has valid values
warning('Interpolation resulted in NaN values or empty output. Check input data.');
cq(isnan(cq)) = 0; % Replace NaNs with 0
end
% Plot contour only if dimensions match
if size(cq, 1) == size(aq, 1) && size(cq, 2) == size(bq, 2)
contour(aq, bq, cq, 'ShowText', 'on');
colorbar;
title('等高線プロット(スプライン補間)');
xlabel('X座標');
ylabel('Y座標');
else
error('Dimensions of Z data (cq) do not match grid dimensions. Sizes: aq (%d,%d), bq (%d,%d), cq (%d,%d)', ...
size(aq, 1), size(aq, 2), size(bq, 1), size(bq, 2), size(cq, 1), size(cq, 2));
end