Interpolate a 84x60 Cell Array to be 84x120

1 view (last 30 days)
Sean Raffetto
Sean Raffetto on 21 Nov 2016
Commented: Guillaume on 22 Nov 2016
Hello,
I have an 84x60 cell array where each array is a column vector of 512 elements {84,60}(512,1). I want to expand to a 84x120 cell array and keep the 512 elements. Here's how I'm trying to interpolate and it isn't working. What am I doing wrong?
% f = 84;
% r = 31;
% r3 = 120;
for m = 1:f;
for n = 1:r-1;
for nn = 1:r3;
ProbeT3H{m,nn} = interp1(linspace(6,360,60)',ProbeTrH{m,n},linspace(0,360,121)','spline');
end
end
end
Thanks!

Answers (1)

Guillaume
Guillaume on 21 Nov 2016
Edited: Guillaume on 21 Nov 2016
At a guess, since interpolation of a cell array does not mean much, your data is actually 3 dimensional 84x60x512 and you want to interpolate along the 2nd dimension. In that case:
ProbeT3H = interpn(cell2mat(cellfun(@(v) permute(v, [3 2 1]), ProbeTrH, 'UniformOutput', false)), ...
1:size(ProbeTrH, 1), ...
linspace(1, size(ProbeTrH, 2), size(ProbeTrH, 2) * 2), ...
1:numel(ProbeTrH{1}));
The cell2mat business is to convert your cell array into a 3d matrix (the cellfun transform your column vectors into vectors in the 3rd dimension), that is then interpolated with interpn.
If you want the output back as a cell array (why though?):
ProbeT3H = cellfun(@(v) permute(v, [3 2 1]), num2cell(ProbeT3H, [1 2]), 'UniformOutput', false);
  5 Comments
Sean Raffetto
Sean Raffetto on 21 Nov 2016
I don't notice any typos, but I'm still getting an error stating "input data has inconsistent size". The reason for using a cell array is because that's how I've written the rest of the code after this interpolation.
Is there a way to do this using my cell array format? I've used the interp1 command to change to my {84x60}(512,1) data. The 512 elements varied originally. Here's how I did that part:
%Theta is linspace(0,360,513) and removing the 513th element for a total of 512
for n = 1:r-1;
for m = 1:f;
ProbeYH{m,n} = interp1(ProbeC{m,n}(:,2),ProbeYrH{m,n},Theta,'spline')
end
end
Guillaume
Guillaume on 22 Nov 2016
There's no point to a cell array if all the cells contain matrices of the same size. Anything you can do with the cell array, you can do easier with a matrix. Case in point, if you had a 3D matrix, the interpolation would be just one line with no loop required.
If you get an error from cell2mat (please always give the full error message so we don't have to guess), then it is because one the cell is not the same size as the others. In that case, I'm not sure how you're going to interpolate that different size cell even if you keep the cell format and use a loop.
You can find the locations of the different size cells with:
[rows, columns] = find(cellfun(@(v) ~isequal(size(v), size(ProbeTrH{1})), ProbeTrH))

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!