Locate in a cell array rows which share same strings and elements
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have a cell array in MATLAB of the following type:
Station_Name Node_Number Generation_type Generated_Power (MW)
Barry 5 Gas 120
Brigg 3 Nuclear 135
Brixton 1 Gas 110
Shoreham 2 Solar 90
Kelsey 5 Gas 85
Jinnie 4 Nuclear 65
Pollock 2 Gas 150
Surret 2 Gas 160
(The actual problem contains much more stations, nodes, and generation types though I am writing this here for simplification).
I want to sort the data to an array of the following type:
Node_Number Generation_type Total_Generated_Power
1 Solar
1 Gas
2 Hydro
2 Gas
.
.
.
3
4
5
So I want to create a script that will automatically produce an array with a different row for each generation type, for each one of the nodes of the cell array (Actually more than 5 nodes and more than 3 generation types).
My initial thought is that I need to make a for loop that will initially check for the elements that are same at the second column, and for those elements the strings at the third column will be compared to see which are the same. Then for those stations that share the same generation type at the same node their generated power will be added together. Then a new variable will need to be created as the new array which will hold the total generated power for each type in each node.
The for loop would be initialised from 1 till the max number of nodes, and would check each one of the rows of the array. The use of the `strcmp` for finding the stations that share the same string i.e same generation type should also be used, from what I understand.
Any tips on how to approach this would be very helpful. Thank you in advance for your time.
0 件のコメント
回答 (1 件)
Walter Roberson
2018 年 2 月 3 日
編集済み: Walter Roberson
2018 年 2 月 3 日
... though for something like that I would probably tend to use several unique() calls and accumarray()
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!