フィルターのクリア

compare matrices of different sizes

14 ビュー (過去 30 日間)
Timothy Dunning
Timothy Dunning 2023 年 4 月 19 日
編集済み: chicken vector 2023 年 4 月 20 日
I'm generating matrices of different sizes to determine the effect of changing the step size on the accuracy of an iterative solution. I want to compare each matrix with an initial one that i know is accurate. Here is how i was planning to do it:
uCompare=interp2(xInitial,tInitial,uInitial,x,t,"cubic"); %make comparison matrix size equal to new matrix
error=mean(abs((uCompare-u) ./ uCompare)); %find mean % error between matrices
where xInitial and tInitial are the x and y values where the initial matrix uInitial is and x and t are the x and y values of the new matrix. xInitial is the same length as uInitial but 1 row and tInitial is the same height as uInitial but 1 column. The 2d interpolation gives this error:
Error using griddedInterpolant/parenReference
Query coordinates input arrays must have the same size.
Error in interp2 (line 156)
Vq = F(Xq,Yq);
Error in stepFind (line 28)
uCompare=interp2(xInitial,tInitial,uInitial,x,t,"cubic");
What is wrong with the data I'm inputting or is there a better way of achieving this?

採用された回答

chicken vector
chicken vector 2023 年 4 月 19 日
編集済み: chicken vector 2023 年 4 月 20 日
Hard to tell from the information you give, but it looks like you are using vectors as interpolation base, when you have to use matrices, so try do adjust the following to your code:
[xGridInitial, tGridInitial] = meshgrid(xInitial, tInitial);
uCompare = interp2(xGridInitial, xGridInitial, uInitial, x, t, "cubic");
Read interp2 documentation about this, but xGridInitial, tGridInitial and uInitial must have same size.
  1 件のコメント
Timothy Dunning
Timothy Dunning 2023 年 4 月 19 日
Thanks, should x and t be matrices as well or are they fine as vectors?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by