Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How I can fix "Matrix dimension must be agree"

1 visualizzazione (ultimi 30 giorni)
Haider Ali
Haider Ali il 25 Mar 2019
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commenti
Rik
Rik il 25 Mar 2019
'Answer' by Haider Ali moved to comment section:
But it shows error to me. I have matlab 2014. Does it makes any difference?

Risposte (1)

Rik
Rik il 25 Mar 2019
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