You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Index problem help?
1 view (last 30 days)
Show older comments
Accepted Answer
Guillaume
on 22 Sep 2015
Edited: Guillaume
on 22 Sep 2015
Possibly, you meant to write
Pl(i,j) = P(i)*B(i,j)*P(j)
Or possibly, you meant something else entirely. It's impossible to tell with so little information.
Most likely also, the loops are not needed and it can all be done with matrix operations.
17 Comments
Walter Roberson
on 22 Sep 2015
You vectorized your code and you did not show us the new code. We can't tell you what needs to be fixed.
Walter Roberson
on 22 Sep 2015
That code will not generate the error message you indicate.
Why did you not follow the conversation in http://www.mathworks.com/matlabcentral/answers/241944-using-summation-and-modulus
Note that you are doing a test of one vector compared to another. You would get a matrix dimensions must agree error there but not an inner dimensions must agree error.
If you were to switch so the two vectors are the same orientation then you face the problem that the test
if A < B
means the same as
if all(A < B)
and is only true if the comparison holds for every item in the vector.
JL555
on 22 Sep 2015
Actually the link to that answer is not valid anymore something terribly wrong with that program and i have a new one.And yes i'm getting a matrix dimension must agree ...so it is not possible to use the 'lt' to generate a matrix of 1x6 or should i compare with only one elemnt of that matrix?
Walter Roberson
on 22 Sep 2015
if pmin(:) < Pi(:)
Walter Roberson
on 22 Sep 2015
It is obvious to me from the code that you should be rewriting using matrix algebra. But every time I fix your code for you, you change it completely and look like you have not understood anything I wrote. You also do not answer questions about what size of output you are expecting from each step. It leaves me reluctant to assist.
JL555
on 22 Sep 2015
Edited: Walter Roberson
on 22 Sep 2015
function [Ft Pi Pl]=FPAeld(x)
global objfun data pmin pmax Pd B B0 Boo
n=length(data(:,1));
[m n1]=size(x);
Pi=x(1:m,1:n1);
for i=1:n
for j=1:n
if data(1,4)<Pi;
data(1,4)=Pi;
else if Pi<data(1,5);
Pi=data(1,5);
C=Pi(i)*B(i,j)*Pi(j);
C1=B0(i)*Pi(i);
Pl=C+C1+Boo;
Pi=Pd+Pl;
end
end
end
end
a=data(:,1);
b=data(:,2);
c=data(:,3);
e=data(:,6);
f=data(:,7);
for i=1:n,
Pi=[Pi Pi(i)];
Ft=a(i)+b(i)*Pi(i)+c(i)*Pi(i).^2+abs(e(i)*sin(f(i)*(pmin-Pi(i))));
end
ok here the new code .....i'm feeding 'x' from an algorithm..its a 6x1 matrix. What i need in the end is Pi value which will have 6 values and i'll feed that value to the Ft formula in the end
Walter Roberson
on 22 Sep 2015
Pi is a vector but if the if comparing it to data(1,4) holds then you assign data(1,4) to replace ALL of the vector.
Walter Roberson
on 22 Sep 2015
Why not just assign
Pi = x;
Since you use all of x?
Walter Roberson
on 22 Sep 2015
I explained several days ago why
Pi=[Pi Pi(i)];
is going to just end up copying the same element over and over again. You are ignoring everything I write about why your program is not working.
Walter Roberson
on 22 Sep 2015
I am not familiar with economic load dispatch.
Note: I am not "dude". Or "man".
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)