Matrix interpolation in the direction of the third dimension
Mostra commenti meno recenti
Hello!
I would like to perform matrix (n x n) interpolation in the direction of the third dimension which is frequency (1 x N), in a way to obtain intermediate matrices which are the interpolated ones. In my case I need to perform quadratic interpolation method which is not provided in interp1, and the use of polyfit together with polyval needs vectors while I have matrices. any ideas how can I proceed? Thank you very much!
3 Commenti
Matt J
il 19 Giu 2019
It's not clear what you are doing, because ...
and the use of polyfit needs vectors
... polyfit doesn't do interpolation, it does curve fitting.
which is not provided in interp1
... interp1 doesn't do curve fitting, it does interpolation.
Jan
il 19 Giu 2019
@Ano: Please mention, what your inputs are. You can use polyfit to get the scaling factors for each matrix.
John D'Errico
il 24 Giu 2019
Please don't add answers just to respond to an answer. Note that multiple people have made COMMENTS. Learn to use them.
Risposte (1)
Gert Kruger
il 19 Giu 2019
Here is my attempt at answering your question. I imagine that there are N matrices each with size nxn.
Example matrices:
%%
n = 10; %Matrix size
N = 5; %Number of matrices
%% Generate example matrices
for count = 1:N
CM{count} = rand(n) ; %CM Cell array matrices
end
Then we fit quadratic functions along the third dimension.
%% Generate fits along the third dimension
temp_ar = zeros(1, N);
for x = 1:n
for y = 1:n
for z = 1:N
temp_ar(z) = CM{z}(x, y);
end
Cfit{x, y} = fit( (1:N)', temp_ar', 'poly2');
end
end
Interpolation is achieved by evaluating the fitted functions:
%% Output matrix generation
%For example output matrix, A, must be 'halfway' between 2nd and 3rd input matrices
A = zeros(n);
z = 2.5; %Evaluation depth
for x = 1:n
for y = 1:n
A(x, y) = Cfit{x, y}(z);
end
end
We can test the output matrix, by using the norm:
norm(CM{2} - A)
norm(CM{3} - A)
norm(CM{5} - A)
Note, that the measure of the difference for the first two is less than for the last one, because the matrix A slice is 'further away' from that depth.
3 Commenti
John D'Errico
il 24 Giu 2019
Ano's answer moved to a comment:
Hello !
Thank you very much for your reply!
The code you proposed seems like exactly what I have been looking for, but when I perform a small test the new added matrices (the interpolated ones) differ greatly from the original values. Here is an example of the resylts I get
CM{1} =[1 4; 5 6];
CM{2}= [1 5; 8 9];
CM{3}= [1 3; 2 11];
while the obtained matrix A is such that
A(:,:,1) =
1.0000 -7.7188
-30.1563 12.0938
A(:,:,2) =
1.0000 -56.7187
-177.1563 5.0938
Note that A(:,:,1) must be inserted between CM{1} and CM{2} , while A(:,:,2) must be inserted between CM{2} and CM{3} . the difference between the entries of A and CM is big while they must in my case represent the same final matrix (2x2x5). any ideas ?!
Best regards!
Gert Kruger
il 27 Giu 2019
Ano,
the matrices A in my proposed answer is generated from the CM matrices. In my case, when z=1, A=CM{1} and when z=2 then A=CM{2}.
I don't know what you mean by inserted. Do you instead mean that there are new matrices (sample points) which need to be sorted into the CM matrix list?
Ano
il 28 Giu 2019
Categorie
Scopri di più su Interpolation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!