Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Wrong matrrix dimensions

Subject: Wrong matrrix dimensions

From: Daniel Eliasson

Date: 28 Jan, 2009 12:32:02

Message: 1 of 5

Hello!
I am currently working on a program that calculates areas , forces and torques and so on for hot rolling applications. The program consists of asking the user how many passes should be made, then if the geometry shape should be round or oval and then it should calculate the area for the selected shape and place the answer in a vector "Area".

When i run the program it stops almost at the end when it should calculate the vector "Bredning" i get this message from matlab:

??? In an assignment A(I) = B, the number of elements in B and
 I must be the same.

Error in ==> NyaHotRod_1_1 at 121
Bredning(k)=C(k).*0.98.*(HjdKvot(k)).^(W) %Spread (=Width out / Width in)
*******************************************

can anyone give me some help in this matter. I'm clueless for now..

My matlab Code looks like this for now:

********************************************
N=input('Number of passes?: ');
 
 for k=1:N
    
     geometryform=input(['Choose shape of roll (', int2str(k), '): 1 round, 2 oval: ']);
   %RR Radius Round pass
   %WR Widht round pass
   %HMR Height Material Round
        if geometryform == 1
         D=input('Diameter of roll[mm]: ')*10^-3;
     Diameter(k)=D;
 RR=input(['Radius of round pass(', int2str(k), ')?: '])*10^-3;
 Radius(k)=RR;
 WR=RR*1.1526*2;
 disp(['Width of round pass[mm]: ' num2str(WR)])
 Width(k)=WR;
 HMR=input(['Height of material (round)[mm](', int2str(k), ')?: '])*10^-3;
 Heightmaterial(k)=HMR;
 WMR=input(['Width of material (round)[mm](', int2str(k), ')?: '])*10^-3;
 Widthmaterial(k)=WMR;
 Area(k)=pi.*(HMR/2)^2; %Area calculated for material. pi*r^2. r=HMR/2
     disp('******* ')
        end
 
     if geometryform == 2
         %HMO Height Material Oval
         %WMO Width Material Oval
         %RO Radius Oval pass
         %WO Width Oval pass
         D=input('Diameter of roll[mm]: ')*10^-3;
     Diameter(k)=D;
 RO=input(['Radius of oval pass [mm](', int2str(k), ')?: '])*10^-3;
 Radius(k)=RO;
 WO=input(['Width of oval pass[mm](', int2str(k), ')?: '])*10^-3;
 Width(k)=WO;
 HMO=input(['Height of material (oval)(', int2str(k), ')?: '])*10^-3;
 Heightmaterial(k)=HMO;
 WMO=input(['Width of material (oval)(', int2str(k), ')?: '])*10^-3;
 Widthmaterial(k)=WMO;
 Area(k)=pi.*(0.5.*HMO).*(0.5.*WMO);
 disp('******* ')
     end
     

 end

for k= 2:N%length(Heightmaterial)
    
InHjd(k)=Heightmaterial(k-1) %Height in
UtHjd(k)=Heightmaterial(k) %Height out
HjdDiff(k)=abs((InHjd(k)-UtHjd(k))) %Difference in Height. Abs for not getting negative values
HjdKvot(k)=InHjd(k)/UtHjd(k) %Height in / Height out
MedHjd(k)=0.5*(InHjd(k)+UtHjd(k))%Average Height
InBrd(k)=Widthmaterial(k-1)%22.6*10^-3; %? %Width in
HetHast(k)=794*10^-6/Area(k); %Mtrl Speed
fprintf('Hetans hastighet [m/s]: %3.5f\n', HetHast);

Velo(k)=HetHast(k) %or is it..

%Spread of material (Bredning)
ww(k)=InHjd(k)/(Diameter(k)-UtHjd(k)); % a parameter that changes
W(k)=10.^(-1.269.*((ww(k)).^0.556)*InBrd(k)./InHjd(k));% a parameter that changes
C(k)=1.072+Velo(k).*(0.00341./HjdKvot(k)-0.00296)-0.1043./HjdKvot(k);% a parameter that changes
K=0.98;
Bredning(k)=C(k).*0.98.*(HjdKvot(k)).^(W) %Spread (=Width out / Width in)
UtBrd(k)=Bredning(k)*InBrd(k); %Width out after spread
fprintf('Wu width: %3.5f\n', UtBrd);

MedBrd(k)=0.5*(InBrd+UtBrd) %Average Width of material
KontLgd(k)=sqrt(Diameter(k)*HjdDiff(k)*0.5)

*********************************************

Subject: Wrong matrrix dimensions

From: Shanmugam Kannappan

Date: 28 Jan, 2009 13:13:02

Message: 2 of 5

Hai,

This kind of errors you will get,when you try to assign a vector to a single index.

make sure that the result of this expression(C(k).*0.98.*(HjdKvot(k)).^(W)) is single value.

Regards,

Shan...

"Daniel Eliasson" <danielel@kth.se> wrote in message <glpj82$83v$1@fred.mathworks.com>...
> Hello!
> I am currently working on a program that calculates areas , forces and torques and so on for hot rolling applications. The program consists of asking the user how many passes should be made, then if the geometry shape should be round or oval and then it should calculate the area for the selected shape and place the answer in a vector "Area".
>
> When i run the program it stops almost at the end when it should calculate the vector "Bredning" i get this message from matlab:
>
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
> Error in ==> NyaHotRod_1_1 at 121
> Bredning(k)=C(k).*0.98.*(HjdKvot(k)).^(W) %Spread (=Width out / Width in)
> *******************************************
>
> can anyone give me some help in this matter. I'm clueless for now..
>
> My matlab Code looks like this for now:
>
> ********************************************
> N=input('Number of passes?: ');
>
> for k=1:N
>
> geometryform=input(['Choose shape of roll (', int2str(k), '): 1 round, 2 oval: ']);
> %RR Radius Round pass
> %WR Widht round pass
> %HMR Height Material Round
> if geometryform == 1
> D=input('Diameter of roll[mm]: ')*10^-3;
> Diameter(k)=D;
> RR=input(['Radius of round pass(', int2str(k), ')?: '])*10^-3;
> Radius(k)=RR;
> WR=RR*1.1526*2;
> disp(['Width of round pass[mm]: ' num2str(WR)])
> Width(k)=WR;
> HMR=input(['Height of material (round)[mm](', int2str(k), ')?: '])*10^-3;
> Heightmaterial(k)=HMR;
> WMR=input(['Width of material (round)[mm](', int2str(k), ')?: '])*10^-3;
> Widthmaterial(k)=WMR;
> Area(k)=pi.*(HMR/2)^2; %Area calculated for material. pi*r^2. r=HMR/2
> disp('******* ')
> end
>
> if geometryform == 2
> %HMO Height Material Oval
> %WMO Width Material Oval
> %RO Radius Oval pass
> %WO Width Oval pass
> D=input('Diameter of roll[mm]: ')*10^-3;
> Diameter(k)=D;
> RO=input(['Radius of oval pass [mm](', int2str(k), ')?: '])*10^-3;
> Radius(k)=RO;
> WO=input(['Width of oval pass[mm](', int2str(k), ')?: '])*10^-3;
> Width(k)=WO;
> HMO=input(['Height of material (oval)(', int2str(k), ')?: '])*10^-3;
> Heightmaterial(k)=HMO;
> WMO=input(['Width of material (oval)(', int2str(k), ')?: '])*10^-3;
> Widthmaterial(k)=WMO;
> Area(k)=pi.*(0.5.*HMO).*(0.5.*WMO);
> disp('******* ')
> end
>
>
> end
>
> for k= 2:N%length(Heightmaterial)
>
> InHjd(k)=Heightmaterial(k-1) %Height in
> UtHjd(k)=Heightmaterial(k) %Height out
> HjdDiff(k)=abs((InHjd(k)-UtHjd(k))) %Difference in Height. Abs for not getting negative values
> HjdKvot(k)=InHjd(k)/UtHjd(k) %Height in / Height out
> MedHjd(k)=0.5*(InHjd(k)+UtHjd(k))%Average Height
> InBrd(k)=Widthmaterial(k-1)%22.6*10^-3; %? %Width in
> HetHast(k)=794*10^-6/Area(k); %Mtrl Speed
> fprintf('Hetans hastighet [m/s]: %3.5f\n', HetHast);
>
> Velo(k)=HetHast(k) %or is it..
>
> %Spread of material (Bredning)
> ww(k)=InHjd(k)/(Diameter(k)-UtHjd(k)); % a parameter that changes
> W(k)=10.^(-1.269.*((ww(k)).^0.556)*InBrd(k)./InHjd(k));% a parameter that changes
> C(k)=1.072+Velo(k).*(0.00341./HjdKvot(k)-0.00296)-0.1043./HjdKvot(k);% a parameter that changes
> K=0.98;
> Bredning(k)=C(k).*0.98.*(HjdKvot(k)).^(W) %Spread (=Width out / Width in)
> UtBrd(k)=Bredning(k)*InBrd(k); %Width out after spread
> fprintf('Wu width: %3.5f\n', UtBrd);
>
> MedBrd(k)=0.5*(InBrd+UtBrd) %Average Width of material
> KontLgd(k)=sqrt(Diameter(k)*HjdDiff(k)*0.5)
>
> *********************************************

Subject: Wrong matrrix dimensions

From: Jos

Date: 28 Jan, 2009 13:16:02

Message: 3 of 5

"Daniel Eliasson" <danielel@kth.se> wrote in message <glpj82$83v$1@fred.mathworks.com>...
> Hello!
> I am currently working on a program that calculates areas , forces and torques and so on for hot rolling applications. The program consists of asking the user how many passes should be made, then if the geometry shape should be round or oval and then it should calculate the area for the selected shape and place the answer in a vector "Area".
>
> When i run the program it stops almost at the end when it should calculate the vector "Bredning" i get this message from matlab:
>
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
> Error in ==> NyaHotRod_1_1 at 121
> Bredning(k)=C(k).*0.98.*(HjdKvot(k)).^(W) %Spread (=Width out / Width in)
> *******************************************

Add a breakpoint to the line above and inspect the sizes of all the variables when it stops there during debugging.

Jos

Subject: Wrong matrrix dimensions

From: Tiago Silva

Date: 28 Jan, 2009 13:36:58

Message: 4 of 5

Try W(k) on that line.

Subject: Wrong matrrix dimensions

From: Daniel Eliasson

Date: 28 Jan, 2009 14:30:19

Message: 5 of 5

Tiago Silva <tpss@gmv.es> wrote in message <5415012.1233149888169.JavaMail.jakarta@nitrogen.mathforum.org>...
> Try W(k) on that line.


Thanks, that did work.
I got another question that im struggling with

In this segment of the code. What should i do to make the calculated value for "UtBrd" to become the next new value for "InBrd" ?

So if I calculate UtBrd to 20, now I want that value to take place instead of the value for InBrd in my calculation.




*********
for k=2:N

%Spread of material (Bredning)
ww(k)=InHjd(k)./(Diameter(k)-UtHjd(k)); % a parameter that changes
W(k)=10.^(-1.269.*((ww(k)).^0.556).*InBrd(k)./InHjd(k));% a parameter that changes
C(k)=1.072+Velo(k).*(0.00341./HjdKvot(k)-0.00296)-0.1043./HjdKvot(k);% a parameter that changes
K=0.98;
Bredning(k)=C(k).*K.*(HjdKvot(k)).^(W(k)) %Spread (=Width out / Width in)
UtBrd(k)=Bredning(k).*InBrd(k) %Width out after spread
fprintf('Wu width: %3.5f\n', UtBrd);
end
******************

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us