Interpolate a 84x60 Cell Array to be 84x120
Mostrar comentarios más antiguos
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)
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
el 21 de Nov. de 2016
Sean Raffetto
el 21 de Nov. de 2016
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.
Sean Raffetto
el 21 de Nov. de 2016
Guillaume
el 22 de Nov. de 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))
Categorías
Más información sobre Interpolation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!