Interpolate a 84x60 Cell Array to be 84x120

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!

Respuestas (1)

Guillaume
Guillaume el 21 de Nov. de 2016
Editada: Guillaume el 21 de Nov. de 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 comentarios

Sean Raffetto
Sean Raffetto el 21 de Nov. de 2016
You're correct. I want to interpolate along the 2nd dimension of my 3D matrix so I have a 84x120x512. The 60/120 represents different radii, essentially increasing my sampling size. 60 represents 6 inch radii increasing to 360 so 60 samples. Now I want to increase the resolution to every 3 inches so 120 samples. I also want to include 0 in the interpolation to 120, but still want a 84x120x512. Does the 'c' represent my 60?
Sean Raffetto
Sean Raffetto el 21 de Nov. de 2016
I realized I was reading the code wrong. 'c' is supposed to be my 3D matrix, ProbeTrH. I'm still receiving an error however once I place ProbeTrH in for 'c'. I feel like I need to run this through a for loop? The for loops I have?
Guillaume
Guillaume el 21 de Nov. de 2016
Sorry, the c was meant to be ProbeTrH. Rather than hardcoding the size, I get them from the cell array. Barring any more typo, the above will create a 84x120x512 output for a 84x60x512 input.
Since your data is actually a 3D matrix, why don't you store it as such. Matrices are easier to deal with than cell arrays.
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
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))

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Nov. de 2016

Comentada:

el 22 de Nov. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by