How can I use rmse for two array of different sizes?

15 次查看(过去 30 天)
I want to do a rmse between one vector 2861x1 and one column of a matrix 6x5761. I tried to do use the rmse by the following example, but the results seems to be much wrong. Is there a better way to do compute the RMSE?
RMSE_tsurf = rmse(tr_s(5,:),t_surf,"all");
RMSE_tmid = rmse(tr_m(5,:),t_mid,"all");
RMSE_tbottom = rmse(tr_b(5,:),t_bottom,"all");
  2 个评论
Jan
Jan 2022-11-8
Which one is the "one vector 2861x1"? What does "seems to be much wrong" mean? Before a "better" way can be found, a definition of "god and bad" is required.
DGM
DGM 2022-11-8
What is the relationship between a 2861x1 vector and a 6x5761 array? ... or are you only using one column from the 6x5761 array? If so, the same question applies. What is the relationship between the two vectors?

请先登录,再进行评论。

回答(1 个)

Raj
Raj 2023-8-31
Hi, I understand you are trying to find a rmse of 2 array of different sizes. For doing so, you need to interpolate length of one vector to other to calculate rmse.
Additionally, you can refer to the example below to calculate rmse.
% Example vectors
a = [1, 2, 3, 4, 5];
b = [1.2, 2.3, 3.5, 4.1, 5.2, 6.3, 7.4];
% Determine the minimum size of the vectors
minSize = min(length(a), length(b));
% Trim the vectors to the minimum size
a = a(1:minSize);
b = b(1:minSize);
%c Calculate rmse using rmse function
reqans = rmse(a,b)
reqans = 0.2933
Refer to the documentation link attached below to understand how rmse function works.
I hope this answers your query.
  1 个评论
DGM
DGM 2023-8-31
编辑:DGM 2023-8-31
If I had this pair of related matrices that I wanted to compare:
Would it make sense to compare the first MxN elements?
  • Why should we presume that the two vectors should be registered on their first elements?
  • Why should we truncate the vectors to length instead of interpolating or permuting them?
  • How does this apply when the inputs aren't both aligned along the same dimension?
  • How does this apply when the inputs aren't necessarily vectors?
  • How does this apply when the input lengths aren't integer divisible by each other?
  • How does this apply when the inputs aren't aligned, aren't vectors, and don't have integer-divisible lengths -- as is the case in the question as asked?
% Example vectors
a = (1:10).'; % a column vector
b = repmat([2;4;6],[1 17]); % a matrix with geometry indivisible by the length of a
% Determine the minimum size of the vectors
minSize = min(length(a), length(b)); % using length() is a great way to create bugs
% Trim the vectors to the minimum size
a = a(1:minSize); % a is a column vector
b = b(1:minSize); % now b is a row vector sampled from the columns of b??
% Calculate rmse using rmse function
ans1 = rmse(a,b) % did you expect the output to be a vector?
ans1 = 1×10
4.5277 3.2404 2.9155 4.5277 3.2404 2.9155 4.5277 3.2404 2.9155 4.5277
ans2 = rmse(a,b.') % what about?
ans2 = 3.6469
% what do other functions do when you feed them misaligned inputs?
blah = mse(a,b) % that's not the square of either previous answer
blah = 38.5000
blah = atan2d(a,b) % now the output is a matrix
blah = 10×10
26.5651 14.0362 9.4623 26.5651 14.0362 9.4623 26.5651 14.0362 9.4623 26.5651 45.0000 26.5651 18.4349 45.0000 26.5651 18.4349 45.0000 26.5651 18.4349 45.0000 56.3099 36.8699 26.5651 56.3099 36.8699 26.5651 56.3099 36.8699 26.5651 56.3099 63.4349 45.0000 33.6901 63.4349 45.0000 33.6901 63.4349 45.0000 33.6901 63.4349 68.1986 51.3402 39.8056 68.1986 51.3402 39.8056 68.1986 51.3402 39.8056 68.1986 71.5651 56.3099 45.0000 71.5651 56.3099 45.0000 71.5651 56.3099 45.0000 71.5651 74.0546 60.2551 49.3987 74.0546 60.2551 49.3987 74.0546 60.2551 49.3987 74.0546 75.9638 63.4349 53.1301 75.9638 63.4349 53.1301 75.9638 63.4349 53.1301 75.9638 77.4712 66.0375 56.3099 77.4712 66.0375 56.3099 77.4712 66.0375 56.3099 77.4712 78.6901 68.1986 59.0362 78.6901 68.1986 59.0362 78.6901 68.1986 59.0362 78.6901
blah = immse(a,b) % now the output is an error
Error using immse
A and B must have the same size.
There's a reason this question didn't get answered. It's fine to stretch relevance when answering dead questions, but it's important that a response to an unanswerable question actually acknowledges that the question was flawed. Responding with a solution to the most trivial case without mentioning its limited relevance to the question or its applicability to any similar task makes this seem all the more like AI-generated chaff.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by