How to fix "Error using > Matrix dimensions must agree" ?

3 次查看(过去 30 天)
How to fix the problem?
My code is like this
if load(sun,1) > pv (sun,1); POL = SUM;
yy = load(sun,1) - pv (sun,1); % (Eksik olan Enerjinin Degeri)
yy1(sun,1) = double (yy);
yy2 = sum (yy1); % importanttttttttttttttttttttttttt(Eloss)
QQS = find(yy1<640.0184);
QQa = yy1(QQS);
QQL = find (yy1>640.0184);
QQb = yy1(QQL);
TOtal = sum (QQb);
v = pemfc(find( pemfc > QQa(:,1) , 1 ) ); % very important (Eksik olan enerjinin PEMFC'daki belirli aralikta çalismasi)
x = v ; % (Eksik olan enerjinin - olarak gösterilmesi)
j(sun,1) = double (x); % (toplam Eksik olan enerjinin PEMFC'daki belirli aralikta çalismasi)
h2miktar = (j*(213.3395/640.0184)); %(depo(q,1))
m = double (h2miktar); % (Hidrojen miktari) (m(q,1))
h2t = sum(m); % Toplam Hidrojen Miktari
h2t2 = h2t - (h2+ POL);
RemainingPower = (h2t2*640.0184)/213.3395;
TOTALremain = RemainingPower + TOtal;
Lossofload = TOTALremain/Load;
Q1 =find(m>0);
answer1 = m(Q1);
WWW = sum(answer1);
end
The error shows me the following line:
Error using > Matrix dimensions must agree.
Error in LAST (line 55)
v = pemfc(find( pemfc > QQa(:,1) , 1 ) );
Something is wrong with "QQa" variable. I want to find first maximum value from pemfc file for QQa parameter.
by the way pemfc = [0
14.6160000000000
27.2182400000000
39.5606400000000
51.4483200000000
63.2548000000000
100.1262400000000
150.7378400000000
200.8297600000000
225.743040000000]
and QQa = [60
60
60
60
3.39799267351160
205.646953910377
220.663912150683
206.033491851057 ]
For Firs value of QQa it select first maxumum values like (63.2548000000000)
For second value of QQa it select first maxumum values like (63.2548000000000)
For sixth value of QQa it select first maxumum values like (225.743040000000)
and so on
Thanks in advance.
  4 个评论
Joel Handy
Joel Handy 2019-8-29
pemfc > QQa(:,1)
This code does an elementwise comparison of pemfc and QQa(:,1). Thats why you are getting a matrix dimension error. Generally its worth avoiding for loops (hence the comment and not an official answer), but for the purposes of explaining the problem, what you are really want to do is. . .
for idx = 1:numel(QQa(:,1))
v(idx) = pemfc(find( pemfc > QQa(idx,1) , 1 ) );
end

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by