Cell returns different number of rows in a loop - How to align this?

1 回表示 (過去 30 日間)
Jackson Wo
Jackson Wo 2020 年 11 月 18 日
コメント済み: Jackson Wo 2020 年 11 月 19 日
I am using a third party software command that returns a cell with X rows and 1 column (e.g. 42x1 cell). The rows contain strings that correspond to chemical phases (e.g. ETA, GAMMA_PRIME, etc.). I have set it up in MATLAB to run this computation N times, and so it will produce such a cell N times. However, on some occasions they will be slightly different in that there may be an extra row (e.g. ETA and ETA#2 might appear), therefore creating a cell with a slightly different number of rows. To illustrate this:
Run N = 1, I get 41 phases:
Run N = 2, I get 42 phases (notice everything is the same except there is a MU_PHASE#2 phase in there, shifting things down):
I am also getting numerical quantities for each of these "Phases" and so this addition/subtraction can really mess up my automated code! My question is therefore:
Is there a way to have it "check" the list on each Nth pass and align it by adding/subtracting rows so that, in the end, they all have the same number of rows? For example: Run 1 above does not have a "MU_PHASE#2" but can we add in a "MU_PHASE#2" row anyway and set it to equal 0?
I know this probably has an easy solution, but I have tried for many hours to figure out an appropriate solution but failed to do so. Any help would be greatly appreciated!

採用された回答

the cyclist
the cyclist 2020 年 11 月 18 日
Something like this should help:
% Define the old and new phases info
phases_old = {'eta';'mu'};
phases_new = {'eta';'mu';'mu#2'};
% Identify missing phases from prior run
missing = setxor(phases_old,phases_new);
% Append missing to prior run
phases_old_fixed = [phases_old; missing];
  1 件のコメント
Jackson Wo
Jackson Wo 2020 年 11 月 19 日
Thanks a lot! The "setxor" command is what I needed. You've saved me a lot of time.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by