I'm trying to fill a cell array with different conditions.

I have a spreadsheet with this data, and I want to create a cell array that stores data depending on the bus and the phase. i.e X{1} must be a 3x1 double containing 0, -120 and 120 degrees because 'Bus 1' has all 3 phases (A, B and C). If a Bus does not have all 3 phases, that cell position must contain a vector with the corresponding angles of the phase, 0 for phase A, -120 for phase B and 120 for phase C.
'Bus' 'Phase'
1 A
1 B
1 C
2 A
2 C
3 B
3 C
4 C

Answers (1)

It's unclear what form your data is in. If it's in excel use readtable to import it into matlab.
demodata = table([1; 1; 1; 2; 2; 3; 3; 4], num2cell('ABCACBCC')', 'VariableNames', {'Bus', 'Phase'})
inphase = {'A', 'B', 'C'};
outphase = [0, -120, 120];
[found, where] = ismember(demodata.Phase, inphase);
assert(all(found), 'Unexpected values for phase');
demodata.PhaseNumeric = outphase(where).';
rowfun(@(phase) {phase.'}, demodata, 'GroupingVariables', 'Bus', 'InputVariables', 'PhaseNumeric', 'OutputVariableNames', 'Phase')

This question is closed.

Asked:

on 27 Apr 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!