preallocation?

8 ビュー (過去 30 日間)
katerina jablonski
katerina jablonski 2012 年 6 月 5 日
i'm trying to solve for various parts of a compensated circuit, but some of my formulas are giving me this "preallocate" suggestion. i'm not sure how to do that, or if i need to. i looked it up on matlab help, but i'm unsure how to proceed. any suggestions? these are some of the variables that are giving the error message.
Prline (W)= (((abs(IlineRect))/(sqrt(2))^2)*Rline)
Prw (W)= (((abs(IlineRect))/(sqrt(2))^2)*Rw)
Prsns (W)= (((abs(IlineRect))/(sqrt(2))^2)*Rsns)
jQind (VAR)= (((abs(IlineRect))/(sqrt(2))^2)*jL)
Sload (VA)= (VldRect*(conj(IlineRect)))/2

回答 (4 件)

Walter Roberson
Walter Roberson 2012 年 6 月 5 日
Let numW be the maximum value that will be used for W, and numVA be the maximum value that will be used for VA, and numVAR be the maximum value that will be used for VAR. Then, before the loop that sets those variables,
Prline = zeros(1, numW);
Prw = zeros(1, numW);
Prsns = zeros(1, numW);
jQind = zeros(1, numVAR);
Sload = zeros(1, numVA);
By the way: if all of those variables are in the same loop and refer to the same IlineRect value, then calculate the common value only once:
absIline2 = abs(IlineRect)^2 / 2;
Then
Prline(W) = absIline2 * Rline;
Prw(W) = absIline2 * Rw;
and so on.

the cyclist
the cyclist 2012 年 6 月 5 日
I suggest you read this page from the documentation:

katerina jablonski
katerina jablonski 2012 年 6 月 5 日
yeah i saw that already. i need some more specific help.

katerina jablonski
katerina jablonski 2012 年 6 月 5 日
okay i'll try that. thanks walter!!
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 5 日
See also my optimization suggestion that I edited into the above.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by