Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How I can fix "Matrix dimension must be agree"

1 回表示 (過去 30 日間)
Haider Ali
Haider Ali 2019 年 3 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
A = importdata('msm_19-1250.txt');
d1=A(:,2);
phi1=A(:,3);
theta1=A(:,4);
B = importdata('msm_19-251500.txt');
d2=B(:,2);
phi2=B(:,3);
theta2=B(:,4);
phi2to1 = phi2 - 200;
theta2to1 = (-1)*theta2 + 400;
C = [d1 phi1 theta1];
D = [d2 phi2to1 theta2to1];
E = [C ; D];
M = mean(E);
R = E - M;
SD = std(E);
F = E(:,1);
histogram(F);
hold on;
line([50.33 50.33], [0 120],'color','y');
line([50.3000 50.3000], [0 120],'color','r');
hold off;
figure;
hold on;
G = R(:,2);
histogram(G);
hold off;
% Part d
figure;
hold on;
H = R(:,3);
histogram(H);
line([0.0025 0.0025], [0 100],'color','g');
line([-0.0025 -0.0025], [0 100],'color','g');
line([0.0050 0.0050], [0 100],'color','y');
line([-0.0050 -0.0050], [0 100],'color','y');
line([0.0075 0.0075], [0 100],'color','r');
line([-0.0075 -0.0075], [0 100],'color','r');
hold off;
%Part f
K = (C + D)/2;
Average = K(:,2);
  5 件のコメント
Alex Mcaulley
Alex Mcaulley 2019 年 3 月 25 日
The code works for me
Rik
Rik 2019 年 3 月 25 日
'Answer' by Haider Ali moved to comment section:
But it shows error to me. I have matlab 2014. Does it makes any difference?

回答 (1 件)

Rik
Rik 2019 年 3 月 25 日
Your error is due to the sizes not matching. This can be solved using implicit expansions, which is automatically enabled since R2016b. Consider the sizes of the variables in each step below:
var1 = [494,395,516,434,476,557,413,442,650,433,417,656,267,478,178,423,427];
var2 = [512,430,520,428,500,600,364,380,658,445,432,626,260,477,259,350,451];
E = [var1;var2];%size(E)=2x17
M = mean(E);%size(M)=1x17
%with implicit expansion:
R = E - M;%size(R)=2x17
This is because E is expanded to fit the size of M. Pre-R2016b you have to explicitly tell Matlab to use implicit expansion.
R=bsxfun(@minus,E,M);

Community Treasure Hunt

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

Start Hunting!

Translated by