Processing three-dimensional array

3 ビュー (過去 30 日間)
Yesbol
Yesbol 2017 年 3 月 4 日
編集済み: dpb 2017 年 3 月 6 日
Hello
This question is basically the extension of
dpb provided the solution for two-dimensional array and the code is working just fine. It just needs some modifications to be applied for the new requirements.
Now I have a three-dimensional array 288x55x11. Each column represents the voltages, the rows represent a load and the third subscript represents different penetration levels (ranging from 0% to 100% in steps of 10% which makes the total number of levels amounts to 11).
The code should do the same as in the solution provided by dpb (please refer to the link ), BUT now it should process three-dimensional array to identify the loads which are not within the range and calculate the total number of loads which are not within the range.
Also, it needs to build the matrix nxm where n - %penetration and m - number of loads not within the limits
Basically, the output of the script is expected to look like, for example:
At 0% penetration: Loads not within the range: All is okay. Total number of loads: 0
At 10% penetration: Loads not within the range: Load 4, 7, 9. Total number of loads: 3
At 20% penetration: Loads not within the range: Load 4, 7, 9, 15, 20, 21, 25. Total number of loads: 7
.
.
.
At 100% penetration: Loads not within the range: Load 4, 7, 9, 15, 20, 21, 25, 30, 31, 35, 37, 39, 40, 41, 42, 46. Total number of loads: 16
Once again, 0%, 10%, ..., 100% represent the third subscript of the three-dimensional array, which is of size 288x55x11.
Any help is greatly appreciated.
Thank you.
  3 件のコメント
Yesbol
Yesbol 2017 年 3 月 5 日
Thank you for your comment. 10% includes just 10% in the computation, but to avoid confusions, let's consider levels from 0 to 11 in steps of 1. I tried to use FOR loop, but I didn't manage.
Here is my code:
lo=207; hi=253; % set the limits desired
levels=0:10:100;
plot_matrix=zeros(2,11);
plot_matrix(1,:)=levels;
loads=round(randn(288,4,11)*12+230);
for i=0:11
ix=iswithin(loads(:,:,i),lo,hi); % check all are ok, ix is logical array of locations
isOK=all(ix); % if true, all are ok for each column
if all(isOK)
fprintf('At %d penetration: No consumers with voltage issues\n',i)
else
bad=sum(~isOK); % number that fail each column (load)
fmt=['At %d penetration: Consumers with voltage issues: Load %2d' repmat(', %2d',i,1,bad-1) '\n']; % format string to print offending load(s)
fprintf(fmt,find(isOK==false)) % and print the message
fprintf('At %d penetration: Total number of consumers with voltage issues: %d\n',i,bad) % and the total number of consumers with voltage issues
plot_matrix(2,1)=bad;
end
end
I get this error:
Subscript indices must either be real positive integers or logicals.
I suspect that this is because isOK is logical and i is integer.
Could you give me some hints?
Thank you!
dpb
dpb 2017 年 3 月 5 日
編集済み: dpb 2017 年 3 月 6 日
"Subscript indices must ... be real positive integers..."
The Matlab error message could be more specific; I've noted this to TMW on many occasions but array indices in Matlab are constrained to start at lower bound of 1, not 0. TMW in the error message considers the mathematical definition of 0 as nonpositive but I'd wager most novice users don't think of it just as it wasn't immediately obvious to you; I don't see why the message couldn't say that specifically; you've already error'ed and crashed, the overhead of a little additional processing it presenting the error message specific for a zero array index couldn't possibly be excessive it would seem.
for i=0:11
ix=iswithin(loads(:,:,i),lo,hi);
The first loop value here is out of range; the 11 planes in the array are number 1:11 while there are 12 elements in the 0:11 vector beginning at 0.

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

回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by