Array multiplication returning single value

6 ビュー (過去 30 日間)
John Antwniou
John Antwniou 2022 年 4 月 9 日
編集済み: John Antwniou 2022 年 4 月 10 日
Greetings,
I want AResult to be a 1x7 array but it keeps returning me a 1x1 value. I split the calculations on different variables (A1,A2,A3 Temp) so I can see it more cleary. I even tried the math on a calculator and the result was what I expected, an 7x1 array.
What am I missing?
Thanks!
EDIT: Well I am dumb, I read the equation wrong so the result was bound to be wrong. I identified my mistake and it was easy to fix.
XData = xlsread('MCP.xlsx');
X1 = XData(:,4)
X2 = XData(:,5)
X3 = XData(:,6)
X4 = XData(:,7)
X5 = XData(:,8)
X6 = XData(:,9)
Perq = XData(:,10) %Every X and the Perq variable are 209x9 arrays
Specs = [X1, X2, X3, X4, X5, X6];
Specs(:,7) = ones(length(XData),1) %Irrelevant but I add a column of 1s at the end of Specs
A1Temp = transpose(Specs'*Perq)
A2Temp = Specs'
A3Temp = A1Temp * A2Temp
AResult = A3Temp * Perq

回答 (2 件)

Torsten
Torsten 2022 年 4 月 10 日
Specs ~ n x 7
A1Temp ~ 1 x 7
A2Temp ~ 7 x n
A3Temp ~ 1 x n
AResult ~ 1 x 1
  2 件のコメント
John Antwniou
John Antwniou 2022 年 4 月 10 日
編集済み: John Antwniou 2022 年 4 月 10 日
I need AResult to be 7 x 1 . I just can't figure it out. I keep geting 1x1 or nxn
Torsten
Torsten 2022 年 4 月 10 日
編集済み: Torsten 2022 年 4 月 10 日
I can now arbitrarily manipulate your arrays for that you get a 7x1 result, but I think it should also make sense in the context.
Don't think about how you get AResult as 7x1 - think about what AResult represents in connection to the other arrays.

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


Bruno Luong
Bruno Luong 2022 年 4 月 10 日
"What am I missing?"
Use elementwise multiplication ".*" and not matrix multiplication "*" (remove the double quote).

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by