MATLAB Answers

0

Why is subtracting different sized matrices not giving me an error? What is matlab calculating?

Nasim Mirzajani さんによって質問されました 2019 年 5 月 21 日
最新アクティビティ James Tursa
さんによって 回答されました 2019 年 5 月 21 日
I was trying to write up a code for R^2 analysis and when calculating residual sum of squares I realised my model data and my real data were not the same size.
Yet somehow matlab is calculating something and giving me a matric answer. I'm confused about what it's doing. In my code fft_x is a (1000x1 double) and sxx is (1x3328 double) and so is ssres. In an ideal world where my model data and real data match in size, I would have expected a scalar. In this unfortunate case, I was expecting an error. But I'm ot getting an error. What's happening?
ssres=sum((fft_x - sxx).^2);

  0 件のコメント

サインイン to comment.

2 件の回答


回答者: KSSV
2019 年 5 月 21 日
編集済み: KSSV
2019 年 5 月 21 日

What you are doing is not correct. Note that
fft_x - sxx
will be a matrix of size 1000X3328. It will subtract the respective elements. As you are calculating sum, it comes to 1X3328. YOu need to get them to same size either by using interpolation (interp1) or by removing some terms. Note that both the terms should be either row or column arrays.

  0 件のコメント

サインイン to comment.



Translated by