How to interpolation between matrices

조회 수: 6 (최근 30일)
Prince Essemiah
Prince Essemiah 2022년 7월 29일
편집: Stephen23 2022년 7월 30일
Imagine the plot attached below. Each point on this plot represents a a 4x4 matrix that describes the behavior of the plant at that particular point. For a controller design, I have a reference load which I need to track at a given speed (omega).
How do I interpolate to get the specific 4-D matrix at a load point and speed which is not already a point on the plot?
Thanks!

채택된 답변

Stephen23
Stephen23 2022년 7월 29일
Assuming that you want to interpolate between the corresponding elements of those 4x4 matrices, then you could do something like this:
C = {randi(9,4,4), randi(9,4,4), randi(9,4,4)}; % 4x4 matrices in a cell array
C{:}
ans = 4×4
2 8 7 7 7 1 5 7 7 8 5 5 3 3 2 7
ans = 4×4
1 3 7 1 3 1 5 6 4 3 9 7 9 4 2 5
ans = 4×4
5 3 4 5 2 3 9 3 7 9 6 2 2 3 9 6
L = [1;3;2]; % load
W = [7;8;9]; % omega
M = cat(3,C{:});
[X,Y] = meshgrid(1:numel(C),1:16);
F = scatteredInterpolant(Y(:),L(X(:)),W(X(:)),M(:),'linear','linear');
Interpolate the entire matrix:
Lq = 1.5;
Wq = 7.5;
out = reshape(F({1:16,Lq,Wq}),4,4)
out = 4×4
2.3333 6.3333 6.5000 5.6667 5.5000 1.3333 5.6667 6.1667 6.5000 7.3333 5.8333 4.8333 3.8333 3.1667 3.1667 6.5000
Lq = 2;
Wq = 8;
out = reshape(F({1:16,Lq,Wq}),4,4)
out = 4×4
2.6667 4.6667 6.0000 4.3333 4.0000 1.6667 6.3333 5.3333 6.0000 6.6667 6.6667 4.6667 4.6667 3.3333 4.3333 6.0000
  댓글 수: 2
Prince Essemiah
Prince Essemiah 2022년 7월 29일
Thank you for your detailed answer. One question though, is the '3' in the concatenated line from having three matrices in C? In other words, what would that number be if my cell array C contains 20 matrices?
M = cat(3,C{:});
Stephen23
Stephen23 2022년 7월 30일
편집: Stephen23 2022년 7월 30일
"is the '3' in the concatenated line from having three matrices in C?"
No, it means that we concatenate those matrices along the third dimension.
"In other words, what would that number be if my cell array C contains 20 matrices?"
3

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by