Error using - Matrix dimensions must agree. Error in WDO_SG_Code_PL_test1m (line 322) a2=aa-a1; i got the error my code segment is below can any one help me why this error came?

sorry i can not paste the whole code this is a segment of code _______________________________________________________________
u(hour)=hour;
Clothesdryer(hour)=power_pattern(hour,1);
a1=find(Clothesdryer);
Dish_washer(hour)=power_pattern(hour,2);
b1=find(Dish_washer);
Washing_Machine(hour)=power_pattern(hour,3);
c1=find(Washing_Machine);
oven(hour)=power_pattern(hour,4);
d1=find(oven);
iron(hour)=power_pattern(hour,5);
e1=find(iron);
Refrigerator(hour)=power_pattern(hour,6);
f1=find(Refrigerator);
Lightening(hour)=power_pattern(hour,7);
g1=find(Lightening);
Vaccume_cleaner(hour)=power_pattern(hour,8);
h1=find(Vaccume_cleaner);
PoolPump(hour)=power_pattern(hour,9);
i1=find(PoolPump);
EWH(hour)=power_pattern(hour,10);
j1=find(EWH);
Hairdryer(hour)=power_pattern(hour,11);
k1=find(Hairdryer);
AC(hour)=power_pattern(hour,12);
L1=find(AC);
%------------------------------------------% % xlswrite(filename1,WHeate)
end
Indexx
a2=aa-a1;
% a3=sum((a2)/9);
b2=bb-b1;
c2=cc-c1;
d2=dd-d1;
e2=ee-e1;
f2=ff-f1;
g2=gg-g1;
h2=hh-h1;
i2=ii-i1;
j2=jj-j1;
k2=kk-k1;
L2=LL-L1;
BAR(2,1)=sum_E_Cost_SS;

3 Comments

Determine the sizes of aa and a1 with the help of the size command and see whether they are equal.
(Most probably they are not).
Best wishes
Torsten.
>> size(aa)
ans =
1 9
>> size(a1)
ans =
1 3
>> size(a2) Undefined function or variable 'a2'. thanks torsten,i do this can u help me more as 1 9-1 3 should be ok
But how to subtract an 1x3 array from an 1x9 array ? Impossible.
Best wishes
Torsten.

Sign in to comment.

Answers (1)

Check the sizes by adding
whos aa
whos a1
before the a2=aa-a1; line.
aa and a1 must have the same size, otherwise you get the error.

4 Comments

>> whos aa Name Size Bytes Class Attributes
aa 1x9 72 double
>> whos a1 Name Size Bytes Class Attributes
a1 1x3 24 double
>> whos a2=aa-a1; >> whos a2=aa-a1 >> whos a2 >>
Thorsten i not understand if sizes is not equal then i have to make them equal and check the above code
Zafar, you want to subtract 3 values from 9 values. That's not defined. One way to handle this would be
len = min([numel(aa) numel(a1]);
a2 = aa(1:len) - a1(1:len);
But I have no idea whether this makes sense in your code.
Maybe something needs to be fixed in the computation of aa and a1 such that they cannot have different sizes.

Sign in to comment.

Categories

Products

Asked:

zz
on 2 Dec 2015

Edited:

on 3 Dec 2015

Community Treasure Hunt

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

Start Hunting!