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:
for loop with division operation

Subject: for loop with division operation

From: L

Date: 6 May, 2013 17:44:08

Message: 1 of 2

I am trying to write a for loop , this is what I have and I am getting an error:

for i=794:-1:1
numlcv=lcvp./largecapvali(i)*notional;
end

you need to know that

lcvp = 0.0913540020817761
0.0694197558922713
0.0419394804007257
0.0377432187205246
0.0334770360148037
0.0288414235561235
0.0229267277929967
0.0222924092522307
0.00882470927416890

notional=500000000
largecapvali= a matrix of 10 rows and 794 columns


The error I receive is the following

Error using ./
Matrix dimensions must agree.

I believe that the issue is the lcvp is a 10 x 1 matrix
and i need to divide by largecapvali(:,794)
 then start again and divide lcvp by largecapvali(:,793)
and so on until i goes from 794 to 1 by -1.

when I check the data in my largecapvali it is a 10x794 matrix but
my value of numlcv only seems to have the values of
lcvp./largecapvali(:,1).

Any help would be appreciated and I thank you in advance.

Subject: for loop with division operation

From: Barry Williams

Date: 7 May, 2013 10:37:09

Message: 2 of 2

"L" wrote in message <km8q58$1k3$1@newscl01ah.mathworks.com>...
> I am trying to write a for loop , this is what I have and I am getting an error:
>
> for i=794:-1:1
> numlcv=lcvp./largecapvali(i)*notional;
> end
>
> you need to know that
>
> lcvp = 0.0913540020817761
> 0.0694197558922713
> 0.0419394804007257
> 0.0377432187205246
> 0.0334770360148037
> 0.0288414235561235
> 0.0229267277929967
> 0.0222924092522307
> 0.00882470927416890
>
> notional=500000000
> largecapvali= a matrix of 10 rows and 794 columns
>
>
> The error I receive is the following
>
> Error using ./
> Matrix dimensions must agree.
>
> I believe that the issue is the lcvp is a 10 x 1 matrix
> and i need to divide by largecapvali(:,794)
> then start again and divide lcvp by largecapvali(:,793)
> and so on until i goes from 794 to 1 by -1.
>
> when I check the data in my largecapvali it is a 10x794 matrix but
> my value of numlcv only seems to have the values of
> lcvp./largecapvali(:,1).
>
> Any help would be appreciated and I thank you in advance.

I had to count the number of elements in lcvp a couple of times, but what you are showing is not 10 x 1. It's 9 x 1. This will generate an error that Matrix dimensions must agree.

Barry

Tags for this Thread

No tags are associated with 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